题目1047:素数判定----------------------一定不要忘了对负数,0,1的判断
AC:
#include<iostream> #include<cmath> using namespace std; int main() { int n; while(cin>>n) { if (n<2) cout<<"no"<<endl; else { int k=(int)sqrt(n*1.0); int i=0; for (i=2;i<=k;i++) if (n%i==0) break; if (i>k) cout<<"yes"<<endl; else cout<<"no"<<endl; } } return 0; }