HDU 2012 素数判定
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
int x = in.nextInt();
int y = in.nextInt();
if((x>=-39 && x<=50) && (y>=-39 && y<=50) && x<=y) {
if(x==0 && y==0) {
continue;
}else {
PrimNumberJudge(x,y);
}
}
}
}
public static void PrimNumberJudge(int x, int y) {
boolean flag = true;
for(int i=x;i<=y;i++) {
int sum = i*i + i + 41;
int sum1 = sum/2 + 1;
for (int j=2;j<sum1;j++) {
if(sum % j==0) {
flag = false;
break;
}
}
}
if(flag==true) {
System.out.println("OK");
}else {
System.out.println("Sorry");
}
}
}