a007
#include<iostream>
#include<math.h>
using namespace std;
int main(){
int a,b;
bool p=true;
int test=2;
while(cin>>a){
p = true;
b = sqrt(a);
if(a == 0 || a== 1){
cout<<"非質數"<< endl;
}
else if(a == 2){
cout<<"質數"<< endl;
}
else{
while(p){
if(( a%test) == 0){
p = false;
cout<<"非質數"<< endl;
}
if(test>b){
p = false;
cout<<"質數"<< endl;
}
test++;
}
}
test = 2;
}//while
}
留言
張貼留言