PAT NowCoder小定律 (水题) - 详细题解

很水的题, 注意闭区间

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
#define ms(x, n) memset(x,n,sizeof(x));
typedef  long long LL;
const LL maxn = 1e9;

bool isPrime(int n)
{
    if(n == 1 ) return false;
    for(int i = 2; i <= sqrt(n); i++)
        if(n%i == 0)
            return false;
    return true;
}

int main()
{
    int x, y;
    while(cin >> x >> y && (x!=0||y!=0)){
        bool flag = 1;
        for(int i = x; i <= y; i++)
            if(!isPrime(i*i+i+41)){
                flag = 0;
                break;
            }
        if(!flag) cout << "Sorry" << endl;
        else cout << "OK" << endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/a1097304791/article/details/83998559