Problem description
For the expression n ^ 2 + N + 41, when n is in the range of (x, y), an integer (including X and Y) is obtained) (-39 <= x <Y <= 50), determines whether the value of this expression is a prime number.
Input
There are multiple groups of input data. Each group occupies one row and consists of two integers x and y. When x = 0 and Y = 0, the input is complete and the row is not processed.
Output
For values in each given range, if the expression value is a prime number, "OK" is output; otherwise, "sorry" is output, and each group of output occupies one row.
Sample Input
0 1
0 0
Sample output
OK
1 #include <stdio.h> 2 #include <string.h> 3 #include <math.h> 4 #define N 3000 5 6 int main(){ 7 char flag[N]; 8 int i; 9 int j;10 int a;11 int b;12 int mark;13 int temp;14 15 memset(flag,‘0‘,N);16 flag[0]=‘1‘;17 flag[1]=‘1‘;18 19 for(i=2;i<=sqrt(N);i++){20 if(flag[i]==‘0‘){21 for(j=i*i;j<N;j+=i)22 flag[j]=‘1‘;23 }24 }25 26 while(1){27 mark=0;28 scanf("%d%d",&a,&b);29 30 if(a==0 && b==0)31 break;32 33 for(i=a;i<=b;i++){34 if(flag[i*i+i+41]!=‘0‘)35 mark=1;36 }37 38 if(mark==1)39 printf("Sorry\n");40 41 else42 printf("OK\n");43 44 }45 46 return 0;47 }
Prime Number Determination