From 9784c8136c77f0e69858ce58ae94b38778b52665 Mon Sep 17 00:00:00 2001 From: Mayank Singh Date: Wed, 2 Dec 2026 23:28:36 +0530 Subject: [PATCH 1/3] fix(maths): use overflow-safe Euclidean GCD in LeastCommonMultiple --- .../maths/LeastCommonMultiple.java | 195 +++++++++++++++--- .../maths/LeastCommonMultipleTest.java | 48 ++++- 2 files changed, 216 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java b/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java index 9ec11e9b3220..1ba2a2f2b16f 100644 --- a/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java +++ b/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java @@ -1,42 +1,185 @@ package com.thealgorithms.maths; +import java.math.BigInteger; +import java.util.Objects; + /** - * Is a common mathematics concept to find the smallest value number - * that can be divide using either number without having the remainder. - * https://maticschool.blogspot.com/2013/11/find-least-common-multiple-lcm.html - * @author LauKinHoong + * Provides overflow-safe methods to compute the Least Common Multiple (LCM) + * of integers in {@code O(log(min(a, b)))} time via the Euclidean GCD + * algorithm. + * + *

Unlike {@code Math.abs(a * b) / gcd(a, b)}, these methods divide before + * multiplying and throw {@link ArithmeticException} if the exact result + * overflows {@code int} or {@code long}. + * + * @see Least common multiple */ public final class LeastCommonMultiple { + private LeastCommonMultiple() { } /** - * Finds the least common multiple of two numbers. + * Finds the non-negative least common multiple of two {@code int} values. * - * @param num1 The first number. - * @param num2 The second number. - * @return The least common multiple of num1 and num2. + *

Returns {@code 0} if either {@code num1} or {@code num2} is {@code 0}. + * + * @param num1 the first number + * @param num2 the second number + * @return the least common multiple of {@code num1} and {@code num2} + * @throws ArithmeticException if the exact result overflows {@code int} */ public static int lcm(int num1, int num2) { - int high; - int num3; - int cmv = 0; - - if (num1 > num2) { - high = num1; - num3 = num1; - } else { - high = num2; - num3 = num2; - } - - while (num1 != 0) { - if (high % num1 == 0 && high % num2 == 0) { - cmv = high; - break; + if (num1 == 0 || num2 == 0) { + return 0; + } + long absA = Math.abs((long) num1); + long absB = Math.abs((long) num2); + long gcd = gcdLong(absA, absB); + // absA and absB are at most 2^31, so (absA / gcd) * absB <= 2^62 < Long.MAX_VALUE. + long result = (absA / gcd) * absB; + return Math.toIntExact(result); + } + + /** + * Finds the non-negative least common multiple of one or more {@code int} values. + * + *

Returns {@code 0} if any element in {@code numbers} is {@code 0}. + * + * @param numbers non-empty array of integers + * @return the least common multiple of all elements + * @throws NullPointerException if {@code numbers} is {@code null} + * @throws IllegalArgumentException if {@code numbers} is empty + * @throws ArithmeticException if the exact result overflows {@code int} + */ + public static int lcm(int... numbers) { + Objects.requireNonNull(numbers, "Input array must not be null."); + if (numbers.length == 0) { + throw new IllegalArgumentException("At least one number is required."); + } + for (int number : numbers) { + if (number == 0) { + return 0; + } + } + int result = Math.toIntExact(Math.abs((long) numbers[0])); + for (int i = 1; i < numbers.length; i++) { + result = lcm(result, numbers[i]); + } + return result; + } + + /** + * Finds the non-negative least common multiple of two {@code long} values. + * + *

Returns {@code 0L} if either {@code num1} or {@code num2} is {@code 0L}. + * + * @param num1 the first number + * @param num2 the second number + * @return the least common multiple of {@code num1} and {@code num2} + * @throws ArithmeticException if the exact result overflows {@code long} + */ + public static long lcm(long num1, long num2) { + if (num1 == 0L || num2 == 0L) { + return 0L; + } + if (num1 == Long.MIN_VALUE || num2 == Long.MIN_VALUE) { + throw new ArithmeticException("long overflow"); + } + long absA = Math.abs(num1); + long absB = Math.abs(num2); + long gcd = gcdLong(absA, absB); + return Math.multiplyExact(absA / gcd, absB); + } + + /** + * Finds the non-negative least common multiple of one or more {@code long} values. + * + *

Returns {@code 0L} if any element in {@code numbers} is {@code 0L}. + * + * @param numbers non-empty array of {@code long} values + * @return the least common multiple of all elements + * @throws NullPointerException if {@code numbers} is {@code null} + * @throws IllegalArgumentException if {@code numbers} is empty + * @throws ArithmeticException if the exact result overflows {@code long} + */ + public static long lcm(long... numbers) { + Objects.requireNonNull(numbers, "Input array must not be null."); + if (numbers.length == 0) { + throw new IllegalArgumentException("At least one number is required."); + } + for (long number : numbers) { + if (number == 0L) { + return 0L; } - high += num3; } - return cmv; + if (numbers[0] == Long.MIN_VALUE) { + throw new ArithmeticException("long overflow"); + } + long result = Math.abs(numbers[0]); + for (int i = 1; i < numbers.length; i++) { + result = lcm(result, numbers[i]); + } + return result; + } + + /** + * Finds the non-negative least common multiple of two {@link BigInteger} values. + * + * @param num1 the first number + * @param num2 the second number + * @return the least common multiple of {@code num1} and {@code num2} + * @throws NullPointerException if either argument is {@code null} + */ + public static BigInteger lcm(BigInteger num1, BigInteger num2) { + Objects.requireNonNull(num1, "First number must not be null."); + Objects.requireNonNull(num2, "Second number must not be null."); + if (num1.signum() == 0 || num2.signum() == 0) { + return BigInteger.ZERO; + } + BigInteger absA = num1.abs(); + BigInteger absB = num2.abs(); + return absA.divide(absA.gcd(absB)).multiply(absB); + } + + /** + * Finds the non-negative least common multiple of one or more {@link BigInteger} values. + * + * @param numbers non-empty array of non-null {@link BigInteger} values + * @return the least common multiple of all elements + * @throws NullPointerException if {@code numbers} or any element is {@code null} + * @throws IllegalArgumentException if {@code numbers} is empty + */ + public static BigInteger lcm(BigInteger... numbers) { + Objects.requireNonNull(numbers, "Input array must not be null."); + if (numbers.length == 0) { + throw new IllegalArgumentException("At least one number is required."); + } + boolean hasZero = false; + for (BigInteger number : numbers) { + Objects.requireNonNull(number, "Elements must not be null."); + if (number.signum() == 0) { + hasZero = true; + } + } + if (hasZero) { + return BigInteger.ZERO; + } + BigInteger result = numbers[0].abs(); + for (int i = 1; i < numbers.length; i++) { + result = lcm(result, numbers[i]); + } + return result; + } + + private static long gcdLong(long a, long b) { + long curA = a; + long curB = b; + while (curB != 0L) { + long remainder = curA % curB; + curA = curB; + curB = remainder; + } + return curA; } } diff --git a/src/test/java/com/thealgorithms/maths/LeastCommonMultipleTest.java b/src/test/java/com/thealgorithms/maths/LeastCommonMultipleTest.java index 73da509723c5..5cf060590adc 100644 --- a/src/test/java/com/thealgorithms/maths/LeastCommonMultipleTest.java +++ b/src/test/java/com/thealgorithms/maths/LeastCommonMultipleTest.java @@ -1,8 +1,11 @@ package com.thealgorithms.maths; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import java.math.BigInteger; import java.util.stream.Stream; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -16,6 +19,49 @@ void testLcm(int num1, int num2, int expected) { } private static Stream provideTestCases() { - return Stream.of(Arguments.of(12, 18, 36), Arguments.of(5, 10, 10), Arguments.of(7, 3, 21), Arguments.of(21, 6, 42), Arguments.of(1, 1, 1), Arguments.of(8, 12, 24), Arguments.of(14, 35, 70), Arguments.of(15, 25, 75), Arguments.of(100, 25, 100), Arguments.of(0, 10, 0)); + return Stream.of(Arguments.of(12, 18, 36), Arguments.of(5, 10, 10), Arguments.of(7, 3, 21), Arguments.of(21, 6, 42), Arguments.of(1, 1, 1), Arguments.of(8, 12, 24), Arguments.of(14, 35, 70), Arguments.of(15, 25, 75), Arguments.of(100, 25, 100), Arguments.of(0, 10, 0), Arguments.of(10, 0, 0), + Arguments.of(0, 0, 0), Arguments.of(-12, 18, 36), Arguments.of(12, -18, 36), Arguments.of(-12, -18, 36), Arguments.of(60_000, 90_000, 180_000)); + } + + @Test + void testIntOverflowThrows() { + assertThrows(ArithmeticException.class, () -> LeastCommonMultiple.lcm(50_000, 50_001)); + assertThrows(ArithmeticException.class, () -> LeastCommonMultiple.lcm(Integer.MIN_VALUE, 1)); + assertThrows(ArithmeticException.class, () -> LeastCommonMultiple.lcm(Integer.MIN_VALUE, 2)); + } + + @Test + void testIntVarargs() { + assertEquals(24, LeastCommonMultiple.lcm(4, 6, 8, 12)); + assertEquals(42, LeastCommonMultiple.lcm(-6, 14, 21)); + assertEquals(0, LeastCommonMultiple.lcm(1_000_000_000, 1_000_000_001, 0)); + assertThrows(NullPointerException.class, () -> LeastCommonMultiple.lcm((int[]) null)); + assertThrows(IllegalArgumentException.class, () -> LeastCommonMultiple.lcm(new int[] {})); + assertThrows(ArithmeticException.class, () -> LeastCommonMultiple.lcm(new int[] {Integer.MIN_VALUE})); + } + + @Test + void testLongLcm() { + assertEquals(6_000_000_000_000L, LeastCommonMultiple.lcm(2_000_000_000_000L, -3_000_000_000_000L)); + assertEquals(0L, LeastCommonMultiple.lcm(Long.MIN_VALUE, 0L)); + assertEquals(60L, LeastCommonMultiple.lcm(12L, -15L, 20L)); + assertEquals(0L, LeastCommonMultiple.lcm(4_000_000_000L, 4_000_000_001L, 0L)); + assertThrows(ArithmeticException.class, () -> LeastCommonMultiple.lcm(4_000_000_000L, 4_000_000_001L)); + assertThrows(ArithmeticException.class, () -> LeastCommonMultiple.lcm(Long.MIN_VALUE, 1L)); + assertThrows(NullPointerException.class, () -> LeastCommonMultiple.lcm((long[]) null)); + assertThrows(IllegalArgumentException.class, () -> LeastCommonMultiple.lcm(new long[] {})); + assertThrows(ArithmeticException.class, () -> LeastCommonMultiple.lcm(new long[] {Long.MIN_VALUE})); + } + + @Test + void testBigIntegerLcm() { + BigInteger a = BigInteger.valueOf(Long.MAX_VALUE); + BigInteger b = BigInteger.valueOf(Long.MAX_VALUE - 1); + assertEquals(a.multiply(b), LeastCommonMultiple.lcm(a, b)); + assertEquals(BigInteger.ZERO, LeastCommonMultiple.lcm(a, BigInteger.ZERO)); + assertEquals(BigInteger.valueOf(60), LeastCommonMultiple.lcm(BigInteger.valueOf(12), BigInteger.valueOf(-15), BigInteger.valueOf(20))); + assertThrows(NullPointerException.class, () -> LeastCommonMultiple.lcm((BigInteger) null, BigInteger.ONE)); + assertThrows(NullPointerException.class, () -> LeastCommonMultiple.lcm(BigInteger.ZERO, null)); + assertThrows(IllegalArgumentException.class, () -> LeastCommonMultiple.lcm(new BigInteger[] {})); } } From 79d6bef139eeeba534b0377d8d339f395c4a61a1 Mon Sep 17 00:00:00 2001 From: Mayank Singh Date: Wed, 2 Dec 2026 23:54:14 +0530 Subject: [PATCH 2/3] fix(maths): resolve SpotBugs/Infer null checks and expand LCM coverage --- .../maths/LeastCommonMultiple.java | 36 +++++++++---------- .../maths/LeastCommonMultipleTest.java | 22 +++++++++--- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java b/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java index 1ba2a2f2b16f..cffdf9857304 100644 --- a/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java +++ b/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java @@ -1,7 +1,6 @@ package com.thealgorithms.maths; import java.math.BigInteger; -import java.util.Objects; /** * Provides overflow-safe methods to compute the Least Common Multiple (LCM) @@ -48,14 +47,12 @@ public static int lcm(int num1, int num2) { * * @param numbers non-empty array of integers * @return the least common multiple of all elements - * @throws NullPointerException if {@code numbers} is {@code null} - * @throws IllegalArgumentException if {@code numbers} is empty + * @throws IllegalArgumentException if {@code numbers} is {@code null} or empty * @throws ArithmeticException if the exact result overflows {@code int} */ public static int lcm(int... numbers) { - Objects.requireNonNull(numbers, "Input array must not be null."); - if (numbers.length == 0) { - throw new IllegalArgumentException("At least one number is required."); + if (numbers == null || numbers.length == 0) { + throw new IllegalArgumentException("Input array must not be null or empty."); } for (int number : numbers) { if (number == 0) { @@ -99,14 +96,12 @@ public static long lcm(long num1, long num2) { * * @param numbers non-empty array of {@code long} values * @return the least common multiple of all elements - * @throws NullPointerException if {@code numbers} is {@code null} - * @throws IllegalArgumentException if {@code numbers} is empty + * @throws IllegalArgumentException if {@code numbers} is {@code null} or empty * @throws ArithmeticException if the exact result overflows {@code long} */ public static long lcm(long... numbers) { - Objects.requireNonNull(numbers, "Input array must not be null."); - if (numbers.length == 0) { - throw new IllegalArgumentException("At least one number is required."); + if (numbers == null || numbers.length == 0) { + throw new IllegalArgumentException("Input array must not be null or empty."); } for (long number : numbers) { if (number == 0L) { @@ -129,11 +124,12 @@ public static long lcm(long... numbers) { * @param num1 the first number * @param num2 the second number * @return the least common multiple of {@code num1} and {@code num2} - * @throws NullPointerException if either argument is {@code null} + * @throws IllegalArgumentException if either argument is {@code null} */ public static BigInteger lcm(BigInteger num1, BigInteger num2) { - Objects.requireNonNull(num1, "First number must not be null."); - Objects.requireNonNull(num2, "Second number must not be null."); + if (num1 == null || num2 == null) { + throw new IllegalArgumentException("Numbers must not be null."); + } if (num1.signum() == 0 || num2.signum() == 0) { return BigInteger.ZERO; } @@ -147,17 +143,17 @@ public static BigInteger lcm(BigInteger num1, BigInteger num2) { * * @param numbers non-empty array of non-null {@link BigInteger} values * @return the least common multiple of all elements - * @throws NullPointerException if {@code numbers} or any element is {@code null} - * @throws IllegalArgumentException if {@code numbers} is empty + * @throws IllegalArgumentException if {@code numbers} is {@code null}, empty, or contains {@code null} */ public static BigInteger lcm(BigInteger... numbers) { - Objects.requireNonNull(numbers, "Input array must not be null."); - if (numbers.length == 0) { - throw new IllegalArgumentException("At least one number is required."); + if (numbers == null || numbers.length == 0) { + throw new IllegalArgumentException("Input array must not be null or empty."); } boolean hasZero = false; for (BigInteger number : numbers) { - Objects.requireNonNull(number, "Elements must not be null."); + if (number == null) { + throw new IllegalArgumentException("Elements must not be null."); + } if (number.signum() == 0) { hasZero = true; } diff --git a/src/test/java/com/thealgorithms/maths/LeastCommonMultipleTest.java b/src/test/java/com/thealgorithms/maths/LeastCommonMultipleTest.java index 5cf060590adc..8e5f3a173b64 100644 --- a/src/test/java/com/thealgorithms/maths/LeastCommonMultipleTest.java +++ b/src/test/java/com/thealgorithms/maths/LeastCommonMultipleTest.java @@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import java.math.BigInteger; +import java.util.function.Supplier; import java.util.stream.Stream; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -27,6 +28,7 @@ private static Stream provideTestCases() { void testIntOverflowThrows() { assertThrows(ArithmeticException.class, () -> LeastCommonMultiple.lcm(50_000, 50_001)); assertThrows(ArithmeticException.class, () -> LeastCommonMultiple.lcm(Integer.MIN_VALUE, 1)); + assertThrows(ArithmeticException.class, () -> LeastCommonMultiple.lcm(1, Integer.MIN_VALUE)); assertThrows(ArithmeticException.class, () -> LeastCommonMultiple.lcm(Integer.MIN_VALUE, 2)); } @@ -34,8 +36,10 @@ void testIntOverflowThrows() { void testIntVarargs() { assertEquals(24, LeastCommonMultiple.lcm(4, 6, 8, 12)); assertEquals(42, LeastCommonMultiple.lcm(-6, 14, 21)); + assertEquals(7, LeastCommonMultiple.lcm(new int[] {-7})); assertEquals(0, LeastCommonMultiple.lcm(1_000_000_000, 1_000_000_001, 0)); - assertThrows(NullPointerException.class, () -> LeastCommonMultiple.lcm((int[]) null)); + Supplier nullIntArray = () -> null; + assertThrows(IllegalArgumentException.class, () -> LeastCommonMultiple.lcm(nullIntArray.get())); assertThrows(IllegalArgumentException.class, () -> LeastCommonMultiple.lcm(new int[] {})); assertThrows(ArithmeticException.class, () -> LeastCommonMultiple.lcm(new int[] {Integer.MIN_VALUE})); } @@ -43,12 +47,16 @@ void testIntVarargs() { @Test void testLongLcm() { assertEquals(6_000_000_000_000L, LeastCommonMultiple.lcm(2_000_000_000_000L, -3_000_000_000_000L)); + assertEquals(0L, LeastCommonMultiple.lcm(0L, Long.MAX_VALUE)); assertEquals(0L, LeastCommonMultiple.lcm(Long.MIN_VALUE, 0L)); assertEquals(60L, LeastCommonMultiple.lcm(12L, -15L, 20L)); + assertEquals(9L, LeastCommonMultiple.lcm(new long[] {-9L})); assertEquals(0L, LeastCommonMultiple.lcm(4_000_000_000L, 4_000_000_001L, 0L)); assertThrows(ArithmeticException.class, () -> LeastCommonMultiple.lcm(4_000_000_000L, 4_000_000_001L)); assertThrows(ArithmeticException.class, () -> LeastCommonMultiple.lcm(Long.MIN_VALUE, 1L)); - assertThrows(NullPointerException.class, () -> LeastCommonMultiple.lcm((long[]) null)); + assertThrows(ArithmeticException.class, () -> LeastCommonMultiple.lcm(1L, Long.MIN_VALUE)); + Supplier nullLongArray = () -> null; + assertThrows(IllegalArgumentException.class, () -> LeastCommonMultiple.lcm(nullLongArray.get())); assertThrows(IllegalArgumentException.class, () -> LeastCommonMultiple.lcm(new long[] {})); assertThrows(ArithmeticException.class, () -> LeastCommonMultiple.lcm(new long[] {Long.MIN_VALUE})); } @@ -58,10 +66,16 @@ void testBigIntegerLcm() { BigInteger a = BigInteger.valueOf(Long.MAX_VALUE); BigInteger b = BigInteger.valueOf(Long.MAX_VALUE - 1); assertEquals(a.multiply(b), LeastCommonMultiple.lcm(a, b)); + assertEquals(BigInteger.ZERO, LeastCommonMultiple.lcm(BigInteger.ZERO, a)); assertEquals(BigInteger.ZERO, LeastCommonMultiple.lcm(a, BigInteger.ZERO)); + assertEquals(BigInteger.ZERO, LeastCommonMultiple.lcm(BigInteger.ZERO, BigInteger.TEN, BigInteger.valueOf(15))); + assertEquals(BigInteger.valueOf(7), LeastCommonMultiple.lcm(new BigInteger[] {BigInteger.valueOf(-7)})); assertEquals(BigInteger.valueOf(60), LeastCommonMultiple.lcm(BigInteger.valueOf(12), BigInteger.valueOf(-15), BigInteger.valueOf(20))); - assertThrows(NullPointerException.class, () -> LeastCommonMultiple.lcm((BigInteger) null, BigInteger.ONE)); - assertThrows(NullPointerException.class, () -> LeastCommonMultiple.lcm(BigInteger.ZERO, null)); + Supplier nullBigArray = () -> null; + assertThrows(IllegalArgumentException.class, () -> LeastCommonMultiple.lcm((BigInteger) null, BigInteger.ONE)); + assertThrows(IllegalArgumentException.class, () -> LeastCommonMultiple.lcm(BigInteger.ONE, (BigInteger) null)); + assertThrows(IllegalArgumentException.class, () -> LeastCommonMultiple.lcm(nullBigArray.get())); + assertThrows(IllegalArgumentException.class, () -> LeastCommonMultiple.lcm(BigInteger.TEN, null)); assertThrows(IllegalArgumentException.class, () -> LeastCommonMultiple.lcm(new BigInteger[] {})); } } From 0263d079f92679ece8e212dfb288ac8d11c6d05f Mon Sep 17 00:00:00 2001 From: Mayank Singh Date: Thu, 3 Dec 2026 00:25:04 +0530 Subject: [PATCH 3/3] fix(maths): remove redundant parentheses and cover null varargs element --- .../java/com/thealgorithms/maths/LeastCommonMultiple.java | 4 ++-- .../java/com/thealgorithms/maths/LeastCommonMultipleTest.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java b/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java index cffdf9857304..50fb582e3993 100644 --- a/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java +++ b/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java @@ -35,8 +35,8 @@ public static int lcm(int num1, int num2) { long absA = Math.abs((long) num1); long absB = Math.abs((long) num2); long gcd = gcdLong(absA, absB); - // absA and absB are at most 2^31, so (absA / gcd) * absB <= 2^62 < Long.MAX_VALUE. - long result = (absA / gcd) * absB; + // absA and absB are at most 2^31, so absA / gcd * absB <= 2^62 < Long.MAX_VALUE. + long result = absA / gcd * absB; return Math.toIntExact(result); } diff --git a/src/test/java/com/thealgorithms/maths/LeastCommonMultipleTest.java b/src/test/java/com/thealgorithms/maths/LeastCommonMultipleTest.java index 8e5f3a173b64..fac3ff01aee9 100644 --- a/src/test/java/com/thealgorithms/maths/LeastCommonMultipleTest.java +++ b/src/test/java/com/thealgorithms/maths/LeastCommonMultipleTest.java @@ -75,7 +75,7 @@ void testBigIntegerLcm() { assertThrows(IllegalArgumentException.class, () -> LeastCommonMultiple.lcm((BigInteger) null, BigInteger.ONE)); assertThrows(IllegalArgumentException.class, () -> LeastCommonMultiple.lcm(BigInteger.ONE, (BigInteger) null)); assertThrows(IllegalArgumentException.class, () -> LeastCommonMultiple.lcm(nullBigArray.get())); - assertThrows(IllegalArgumentException.class, () -> LeastCommonMultiple.lcm(BigInteger.TEN, null)); + assertThrows(IllegalArgumentException.class, () -> LeastCommonMultiple.lcm(new BigInteger[] {BigInteger.TEN, null})); assertThrows(IllegalArgumentException.class, () -> LeastCommonMultiple.lcm(new BigInteger[] {})); } }