#include<bits/stdc++.h>

using namespace std;

int main(){

  vector<int> p;

  p.push_back(2);

	for(int i=3;i<=1000000;i+=2){
	  int k=0;
	  for(int j=3;j<=sqrt(i);j+=2)
		{
		  if(i%j==0)
			{
			  k=1;
			  break;
			}
		}
	  
	  if(k==0)
		p.push_back(i);
	}
	
  while(1){

	int n;

	cin >> n;

	if(n == 0)
	  break;

	int sum = 0;
	
	for(int i=0;i<n;++i)
	  sum += p[i];

	cout << sum << endl;
	
  }
	
}

