Java Guava | gcd(long a, long b) of LongMath Class with Examples
The method gcd(long a, long b) of Guava’s LongMath Class returns the greatest common divisor of two parameters a and b.
public static long gcd(long a, long b)
Parameters: This method accepts two parameters a and b of the long type of whose GCD is to be found.
Return Type: This method returns the largest positive long value that divides both of the parameters passed to the function.
Exceptions: The method gcd(long a, long b) throws IllegalArgumentException if a is negative or b is negative.
Note: If a and b both are zero, the method returns zero.
GCD of 14 and 70 is 14 GCD of 23 and 15 is 1
java.lang.IllegalArgumentException: a (-5) must be >= 0