File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed
main/java/com/examplehub/projecteuler
test/java/com/examplehub/projecteuler Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ public class Problem06 {
1616 public static long solution1 (int n ) {
1717 long sumOfSquares = 0 ;
1818 for (int i = 1 ; i <= n ; ++i ) {
19- sumOfSquares += Math .pow (i , 2 );
19+ sumOfSquares = ( long ) ( sumOfSquares + Math .pow (i , 2 ) );
2020 }
2121
2222 long squareOfSum = (long ) Math .pow (SumToN .sum (n ), 2 );
Original file line number Diff line number Diff line change 11package com .examplehub .projecteuler ;
22
3+ import com .examplehub .maths .PrimeCheck ;
4+
35/**
46 * The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
57 * <p>
1012public class Problem10 {
1113 public static long solution1 (int n ) {
1214 long sum = 0 ;
15+ for (int i = 2 ; i <= n ; i ++) {
16+ if (PrimeCheck .isPrime (i )) {
17+ sum += i ;
18+ }
19+ }
20+ return sum ;
1321 }
1422}
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 Problem10Test {
8+
9+ @ Test
10+ void testSolution1 () {
11+ assertEquals (17 , Problem10 .solution1 (10 ));
12+ assertEquals (142913828922L , Problem10 .solution1 (2000000 ));
13+ }
14+ }
You can’t perform that action at this time.
0 commit comments