Problem Description
对于表达式n^2+n+41,当n在(x,y)范围内取整数值时(包括x,y)(-39<=x<y<=50),判定该表达式的值是否都为素数。
Input
输入数据有多组,每组占一行,由两个整数x,y组成,当x=0,y=0时,表示输入结束,该行不做处理。
Output
对于每个给定范围内的取值,如果表达式的值都为素数,则输出"OK",否则请输出“Sorry”,每组输出占一行。
Sample Input
0 1
0 0
Sample Output
OK
Problem Description
对于表达式n^2+n+41,当n在(x,y)范围内取整数值时(包括x,y)(-39<=x<y<=50),判定该表达式的值是否都为素数。
Input
输入数据有多组,每组占一行,由两个整数x,y组成,当x=0,y=0时,表示输入结束,该行不做处理。
Output
对于每个给定范围内的取值,如果表达式的值都为素数,则输出"OK",否则请输出“Sorry”,每组输出占一行。
Sample Input
0 1
0 0
Sample Output
OK
#include <stdio.h>
int main()
{
int x, y, m, n, i, j;
while (scanf("%d%d", &x, &y) != EOF)
{
i = 2;
j = 0;
for (n = x; n <= y; n++)
{
m = n * n + n + 41;
i = 2;//<======================
while (i < m)//<======================
{
if (m % i == 0)
break;
i++;
}
if (i == m)
j = 1;
}
if (j == 1)
{
if (x == 0 && y == 0)
continue;
else
printf("OK\n");
}
if (j == 0)
printf("Sorry\n");
}
return 0;
}