#include <iostream>
#include <cmath>
using namespace std;
int isPrime(const int a){
int flag = 1;
int b = a;
for (int i = 2; i < sqrt(b); i++){
if (b%i == 0) flag=0;
}
return flag;
}
int main(){
int n,x,y,s=0;
while ((cin >> x >> y) && (x != 0 || y != 0))
{
if (x > y){
x = x + y;
y = x - y;
x = x - y;
}
for (int n = x; n <= y; n++){
int m = n*n + n + 41;
if (isPrime(m)) s++;
else break;
}
if (s == y - x + 1) cout << "OK" << endl;
else cout << "Sorry" << endl;
s = 0;
}
return 0;
}
杭电ACM2012:素数判定
最新推荐文章于 2022-11-05 15:12:09 发布