判定素数
没有用非常高效的方法,
只是简单的在2-根号n之间遍历
#include<iostream>
#include<sstream>
#include<cstring>
#include<cctype>
#include<math.h>
#include<iomanip>
using namespace std;
int main(){
int x,y,n;
int flag;
while(cin>>x>>y){
if(x==0&&y==0){break;}
for(int i=x;i<y+1;i++){
flag=0;
n=i*i+i+41;
for(int j=2;j<sqrt((double)n);j++){ //需要强制转换类型
if(n%j==0){
cout<<"Sorry"<<endl;
flag=1;
break;
}
}
if(flag){break;}
}
if(!flag){cout<<"OK"<<endl;}
}
return 0;
}