forked from nayuki/Project-Euler-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp005.java
More file actions
31 lines (22 loc) · 644 Bytes
/
p005.java
File metadata and controls
31 lines (22 loc) · 644 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
* Solution to Project Euler problem 5
* By Nayuki Minase
*
* http://nayuki.eigenstate.org/page/project-euler-solutions
* https://github.com/nayuki/Project-Euler-solutions
*/
import java.math.BigInteger;
public final class p005 implements EulerSolution {
public static void main(String[] args) {
System.out.println(new p005().run());
}
public String run() {
BigInteger allLcm = BigInteger.ONE;
for (int i = 1; i <= 20; i++)
allLcm = lcm(BigInteger.valueOf(i), allLcm);
return allLcm.toString();
}
private static BigInteger lcm(BigInteger x, BigInteger y) {
return x.divide(x.gcd(y)).multiply(y);
}
}