天天看點

杭電 2012 素數判定

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<sstream>
#include<map>
#define endl "\n"
using namespace std;
bool prime(int n){
    int f=n*n+n+41;
    int i;
    for(i=2;i<sqrt(f);i++){
        if(f%i==0){
            break;
        } 
    }
    if(i>=sqrt(f)){
        return true;
    }else{
        return false;
    }
}
int main(){
    int x,y;
    while(cin>>x>>y){
        if(x==0&&y==0){
            break;
        }
        bool flag=true;
        for(int i=x;i<=y;i++){
            if(!prime(i)){
                flag=false;
                break;
            }
        }
        if(flag){
            cout<<"OK"<<endl; 
        }
        else{
            cout<<"Sorry"<<endl;
        }
    }
    return 0;
}