#include <stdio.h>

int main(){

	int count;
	int i;
	int j;
	int n;
	int max;
	int ncount;

	while( 1 ){
		ncount = 0;
		max = 0;
		scanf( "%d" ,&n );
		if( n == 0) break;

		for(i = 1; i < 10000; i++){
			count = 0;
			for(j = 1; j <= i; j++){
				if(i % j == 0){
					count++;
				}
			}

			if(count == 2){
				max += i;
				ncount++;
				if( n <= ncount )break;
			}
		}
		printf("%d\n",max);
	}
	return 0;
}