arr[1<<18];
n=1<<18;
cnt;

main(i,j) {
	memset(arr, -1, sizeof arr);
	arr[0] = arr[1] = 0;
	for(i = 2; i * i <= n; i++)
		if(arr[i])
			for(j = 2 * i; j <= n; j += i)
				arr[j] = 0;

	for(;scanf("%d",&n),n;) {
		cnt = 0;
		for(i = n + 1; i <= 2 * n; i++)
			if(arr[i])
				cnt++;
		printf("%d\n", cnt);
	}
	exit(0);
}