#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(){
    int n;
    while(cin >> n,n){
        int count=0;
        int ans=0;
        vector<int> sosu(0);
        for(int i=2;;i++){
            if(count==n)
                break;
            if(i==2){
                ans+=2;
                sosu.push_back(2);
                count++;
            }
            else{
                for(int j=0;j<sosu.size();j++){
                    if(i%sosu[j]==0)
                        break;
                    if(j==sosu.size()-1){
                    	sosu.push_back(i);
                        ans+=i;
                        count++;
                    }
                }
            }
        }
        cout << ans << endl;
    }
}