import java.lang.Math;
import java.util.ArrayList;

public class Main {

    public static ArrayList<Integer> primes = new ArrayList<>();
    public static int primeSum = 0;

    public static int getSum(int n) {
        int count = 2;
        while (primes.size() != n) {
            //check for prime numbers
            if (isPrime(count)) {
                //add to list of primes
                primes.add(count);
                //add to the sum of primes
                primeSum += count;
            }
            count++;
        }
        return primeSum;
    }

    public static void main(String[] args) {
        final int primeCap = 1000;
        System.out.print(getSum(primeCap));
    }
    
    public static boolean isPrime(int n) {
        //part 1: retrieve the 1st prime
        while (primes.isEmpty()) {
            for (int i = 3; Math.pow(i, 2) <= n; i += 2) {
                if (n % i == 0) {
                    return false;
                }
            }
            return true;
        }
        //part 2: check to see if int n is evenly divisible into any prime in the arraylist
        for (int i = 0; i < primes.size(); i++) {
            if (n % primes.get(i) == 0) {
                return false;
            }
        }
        //if not; then check from the last prime in the list all the way to n
        for (int i = primes.get(primes.size() - 1) + 1; Math.pow(i, 2) <= n; i += 2) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }
}