Skip to content

Commit d9b365b

Browse files
add Problem05
1 parent 988e4c8 commit d9b365b

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.examplehub.projecteuler;
2+
3+
/**
4+
* 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
5+
* <p>
6+
* What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
7+
* <p>
8+
* link: https://projecteuler.net/problem=5
9+
*/
10+
public class Problem05 {
11+
12+
public static long solution1(int n) {
13+
for (int i = n; ; i++) {
14+
for (int j = 1; j <= n; j++) {
15+
if (i % j != 0) {
16+
break;
17+
}
18+
if (j == n) {
19+
return i;
20+
}
21+
}
22+
}
23+
}
24+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.examplehub.projecteuler;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
class Problem05Test {
8+
@Test
9+
void testSolution1() {
10+
assertEquals(2520, Problem05.solution1(10));
11+
assertEquals(360360, Problem05.solution1(15));
12+
assertEquals(232792560, Problem05.solution1(20));
13+
}
14+
}

0 commit comments

Comments
 (0)