#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define MAX 105000
int main(){
  bool prime[MAX + 1] = {};
  int sum = 0, cnt = 0;
  vector< int > vc;
  vc.push_back(2);

  for(int i = 3 ; cnt < 10001 ; i += 2 ){
    if(!prime[i]){
      vc.push_back(i + vc[cnt++]);
      for(int j = 3 ; i * j <= MAX ; j += 2 ){
	prime[i * j] = true;
      }
    }
  }

  int n;
  while(cin >> n , n){
    cout << vc[n - 1] << endl;
  }
}