What would be the easiest way to calculate Greatest Common Divisor and Least Common Multiple on a set of numbers? What math functions can be used to find this information?
Java – How to find GCD, LCM on a set of numbers
greatest-common-divisorjavalcmmath
Related Topic
- Java – Fastest way to determine if an integer’s square root is an integer
- Java – How to read / convert an InputStream into a String in Java
- Java – How to generate random integers within a specific range in Java
- Java – How do servlets work? Instantiation, sessions, shared variables and multithreading
- Easy interview question got harder: given numbers 1..100, find the missing number(s) given exactly k are missing
- What is the fastest way to find the gcd of n numbers
- Java – How to directly initialize a HashMap (in a literal way)
- Java – the difference between canonical name, simple name and class name in Java Class
Best Answer
I've used Euclid's algorithm to find the greatest common divisor of two numbers; it can be iterated to obtain the GCD of a larger set of numbers.
Least common multiple is a little trickier, but probably the best approach is reduction by the GCD, which can be similarly iterated: