File tree Expand file tree Collapse file tree
main/java/com/examplehub/projecteuler
test/java/com/examplehub/projecteuler Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments