#9734: WA 求解


u10300054 (unknown)


#include <iostream>
#include <math.h>
#define max 4795
void findprime(int prime[max])
{
long a,b,c,d,e=0;
int flag=0;
prime[e++]=2;
prime[e++]=3;
prime[e++]=5;
prime[e++]=7;
prime[e++]=11;
prime[e++]=13;
a=15;
while(e<max)
{
flag=0;
c=(int)sqrt(a);
for(b=1;b<=c;b++)
{
if(a%prime[b]==0)
flag=1;
break;
}
if(flag==0)
prime[e++]=a;
a+=2;
}
}
using namespace std;
int main()
{
int a[max],s,d,f;
findprime(a);
while(cin>>s)
{
d=0;
for(f=0;f<3000;f++)
{
if(s==a[f])
{
d=1;
cout<<"質數"<<endl; 
break;
}
}
if(d==0)
cout<<"非質數"<<endl;
}




return 0;
}