Skip to content

Commit d4f0eed

Browse files
add Problem10
1 parent 6cc7801 commit d4f0eed

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/main/java/com/examplehub/projecteuler/Problem06.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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);

src/main/java/com/examplehub/projecteuler/Problem10.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package 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>
@@ -10,5 +12,11 @@
1012
public 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
}
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 Problem10Test {
8+
9+
@Test
10+
void testSolution1() {
11+
assertEquals(17, Problem10.solution1(10));
12+
assertEquals(142913828922L, Problem10.solution1(2000000));
13+
}
14+
}

0 commit comments

Comments
 (0)