#include<iostream>
#include<vector>
using namespace std;

int main(){
  int map[5000000]={};
  for(int i=2; i<=5000000; ++i){
    for(int j=2; i*j<=5000000; ++j){
      map[i*j] = 1;
      //cout << i*j << endl;
    }
  }
  vector<int> iv;
  for(int i=2; i<500000; ++i){
    if(map[i]==0){iv.push_back(i);}
  }
  /* for(auto i: iv){
    cout << i << endl;
    } */
  int n;
  while(cin >> n,n){
    int ans = 0;
    for(int i=0; i<n; ++i){
      ans += iv[i];
    }
    cout << ans << endl;
  }
}

