1 2 3 4 5 17 0
1: no 2: no 3: yes 4: no 5: yes 6: yes
#include <stdio.h>
#define MAX 16100
bool notPrime[MAX] ;
int main()
{
for(int i = 2 ; i < MAX ; ++i)
{
for(int j = 2 ;j*i < MAX ; ++j)
{
notPrime[i*j] = true ;
}
}
notPrime[1] = notPrime[2] = true ;
int n , c=1;
while(~scanf("%d",&n) && n>0)
{
printf("%d: ",c++) ;
if(!notPrime[n])
{
puts("yes");
}
else
{
puts("no") ;
}
}
return 0;
}原文地址:http://blog.csdn.net/lionel_d/article/details/44240273