C++ hdoj 2012 素数判定

来源:互联网 发布:ping mac 获取ip地址 编辑:程序博客网 时间:2024/06/16 23:23
#include<iostream>#include<cmath>using namespace std;int main(){ int x,y,time=1; while(cin>>x>>y) {  if(x==0&&y==0)  return 0;  int n;  for(n=x;n<=y;n++)  {   int a;   a=n*n+n+41;   int i;   for(i=2;i<=sqrt(a);i++)   {    if(a%i==0)    {time=0;     break;}    else     {time=1;}    }   if(time==0)   break;   }  if(time)  cout<<"OK"<<endl;  else  cout<<"Sorry"<<endl;  time=1;  }return 0;}
1 0