题目来源:牛客网 PAT乙级训练题 1011 NowCoder小定律
import java.util.*;
public class Main {
public static boolean isPrime(int x) {
if(x == 1) {
return false;
}
for(int i = 2 ; i * i <= x ; i++) {
if(x % i == 0) {
return false;
}
}
return true;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
int x = sc.nextInt();
int y = sc.nextInt();
boolean isSu = true;
if(x == 0 && y == 0) {
return;
}
for(int i = x ; i <= y ; i++) {
int re = i * i + i + 41;
if(!isPrime(re)) {
isSu = false;
break;
}
}
if(isSu) {
System.out.println("OK");
} else {
System.out.println("Sorry");
}
}
}
}