HDU 2012 判定素数

来源:互联网 发布:需求分析工具 知乎 编辑:程序博客网 时间:2024/04/30 11:52
#include <iostream>using namespace std;int main(){    int n,m;    while(cin>>n>>m&&(n!=0||m!=0)){        int count=0;        for(int i=n;i<=m;i++){            int flag=1;            int sum=i*i+i+41;            for(int j=2;j*j<=sum;j++){                if(sum%j==0)                    flag=0;            }            if(flag==1)                count++;        }        if(count==m-n+1)            cout<<"OK"<<endl;        else            cout<<"Sorry"<<endl;    }    return 0;}

0 0