I need to find least common divisor for a series of numbers (up to 100 000 numbers, each of them is in the range of [0, 2 000 000 000])
I am using the following algorithm lcm(a,b) = (a/gcd(a,b)) * b
The standard method of finding lcm for for than 2 numbers lcm(a, lcm(b,c))... is working for small input values.
However, for large input, it starts giving overflow error even if i used long long int...
How can I avoid having overflow error for many larger integer values?
Thank you for the help
Least common multiple in this case can be a large number with hundreds of digits. You need to handle such big integers.
gmplib
library (-lgmp
) supports arbitrary precision integer arithmetic:Example:
Complete program:
lcm.c