package margusmartseppcode.From_1_to_9;
public class Problem_5 {
static long gcd(long a, long b) {
if (b == 0)
return Math.abs(a);
return gcd(b, a % b);
}
static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
public static void main(String[] args) {
long result = 1;
for (long i = 2; i < 21; i++)
result = lcm(result, i);
System.out.println(result);
}
}
Showing posts with label gcm. Show all posts
Showing posts with label gcm. Show all posts
Tuesday, September 8, 2009
Euler Problem 5 solution
Time (s): ~0.001
Labels:
Euclid algorithm,
Euler Problem 1-9,
gcm,
lcm
Subscribe to:
Posts (Atom)