-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP10.java
More file actions
25 lines (25 loc) · 764 Bytes
/
P10.java
File metadata and controls
25 lines (25 loc) · 764 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
import java.util.Scanner;
import java.util.ArrayList;
public class P10 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("Enter N: ");
int N = s.nextInt() - 2;
int[] primes = new int[N];
for (int i = 0; i < N; i++) {
primes[i] = i+2;
}
for (int i = 0; i < N; i++) {
if (primes[i] != -1) {
for (int j = i; j < N; j+=primes[i]) {
if (i != j && primes[j] % primes[i] == 0) primes[j] = -1;
}
}
}
long sum = 0;
for (int i = 0; i < N; i++) {
if (primes[i] != -1) sum += primes[i];
}
System.out.println(sum);
}
}