#54009: c++答案


yp11351229@yphs.tp.edu.tw (809-39詹豫喬)


#include <iostream>
#include <cmath>
int main(){
	using namespace std;
	cin.tie(0);
int g[5000],t=0,root; //g[5000]存放2到2147483647的質數
bool b=1;
 
	root=sqrt(2147483647);
for(int i=2;i<=root;i++){
		b=1;
for(int j=2;j<=sqrt(i);j++){
if(i%j==0){
				b=0;
break;
			}

		}
if(b) g[t++]=i;//建表
	}

int n;
while(cin>>n){
		b=1;
for(int i=0;i<t;i++){
int sq=sqrt(n);
if(sq<g[i])break;
if(n%g[i]==0){
				b=0;
break;
			}
		}
if(b) cout<<"質數"<<endl;
else cout<<"非質數"<<endl;


	}
return 0;
}