#include<cstdio>
#include<cmath>
using namespace std;

int prime(int n) {
	int i, j, d;
	if (n == 1)return 2;
	d = prime(n - 1);
	for (i = d+1;; i++) {
		for (j = 2;; j++) {
			if (i%j == 0)break;
			if (j == i - 1) { return i; }
		}
	}
}

int main() {
	int n,i, sum = 0;
	while (scanf_s("%d", &n) && n){
		if (n == 0)break;
		for (i = 1; i <= n; i++)sum += prime(i);
		printf("%d\n", sum);
		sum = 0;
	}
	return 0;
}