#include <iostream>
#include <math.h>
using namespace std;
int n,pri=3,d, MAX=46341,number, prime[4800]={0}, large=4795; // 有4795個植樹
int binarySearch(int prime[], int check)
{
int low = 1;
int upper = large;
while(low <= upper) {
int mid = (low+upper) / 2;
if(prime[mid] < check)
low = mid+1;
else if(prime[mid] > check)
upper = mid - 1;
else
return 1;
}
return -1;
}
int main()
{
bool watch=0;
prime[1]=2;
prime[2]=3;
for (d=4, number=1; number+d<=MAX;d=6-d)
{
n=1;
watch=1;
number=number+d;
while (prime[++n]<=sqrt(number))
if (number%prime[n]==0)
{
watch=0;
break;
}
if (watch==1)
prime[pri++]=number;
}
int y;
while (cin>>y)
{
if (y==0)
break;
if (y==1)
cout<<1<<endl;
else
{
if (binarySearch(prime, y)==1)
cout<<0<<endl;
else
cout<<1<<endl;
}
}
return 0;
}
委什麼也在1003行WA