Your program reads one natural numbers n in, and prints out the sum of the first n prime numbers starting from 2.
Input Format:
A positive whole numbers n, which is less than 103.
Output Format:
A number which is the sum of all the first n prime numbers.
Sample Input:
10
Sample Output:
129
129
import java.util.Scanner;
public class Main {
public boolean is_prime(int n) {
if(n < 2) return false;
for (int i = 2; i * i <= n; i ++ )
if(n % i == 0) return false;
return true;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int sum = 0;
Main P = new Main();
for (int i = 2, j = 0; j < n; i ++) {
if(P.is_prime(i)) {
sum += i;
j ++ ;
}
}
System.out.println(sum);
}
}



