-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathProblem_5.java
More file actions
38 lines (23 loc) · 697 Bytes
/
Problem_5.java
File metadata and controls
38 lines (23 loc) · 697 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
32
33
34
35
36
37
38
/*
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
*/
class Problem_5 {
public static int LCM(int n1, int n2) {
int lcm = 0;
for (int i = 1; i < n2; i++) {
lcm = (n1 > i) ? n1 : i;
for (lcm = (n1 > i) ? n1 : i; lcm <= (n1*n2); lcm++) {
if(lcm % n1 == 0 && lcm % i == 0){
n1 = lcm;
break;
}
lcm += 1;
}
}
return lcm;
}
public static void main(String[] args) {
System.out.println(LCM(1, 20));
}
}