#include <cstdio>
#include <cstdlib>
#include <numeric>
#include <vector>
using namespace std;

vector<int> sieve(int n) {
	vector<int> res(1, 2);
	vector<bool> prime(n, true);
	for(int i = 3; i < n; i += 2) {
		if(prime[i]) {
			res.push_back(i);
			for(int j = i * 3; j < n; j += i * 2)
				prime[j] = false;
		}
	}

	return res;
}

int main() {
	vector<int> prime = sieve(110000);
	printf("%d\n", (int)prime.size());

	for(int n; scanf("%d", &n), n;)
		printf("%d\n", accumulate(prime.begin(), prime.begin() + n, 0));

	return EXIT_SUCCESS;
}