Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 91615 Accepted Submission (s): 32165
Problem description for an expression n^2+n+41, when n takes an integer value in the (x, y) range (including x, y) ( -39<=x<y<=50), the value of the expression is determined to be a prime number.
Input data has multiple groups, one row per group, consisting of two integers, x, y, and when x=0,y=0, indicates that the input ends and the row is not processed.
Output for each given range of values, if the value of the expression is a prime number, outputs "OK", otherwise output "Sorry", each set of output in one row.
Sample Input
0 10 0
Sample Output
Ok
#include <stdio.h>
#include <math.h>
int f (int s)
{
int i,j=0,k=0;
//printf ("%d\n", s);
for (i=2;i<=sqrt (s); i++)
if (s%i==0)
j++;
//else k++;
if (j==0)
return 1;
else
return 0;
}
Main ()
{
int x,y,i,j,a,b,c,k;
while (scanf ("%d%d", &x,&y)!=eof)
{
if (x==0&&y==0)
break;
j=0;
k=0;
c=y-x+1;
// printf ("%d\n", c);
for (i=x;i<=y;i++)
{
a=i*i+i+41;
b=f (a);
//printf ("%d", b);
if (b==0)
k++;
//{
// printf ("sorry\n");
// break;
//}
if (b==1)
j + +;
}
// printf ("%d%d\n", j,k);
if (j==c)
printf ("ok\n");
else printf ("sorry\n");
}
return 0;
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Prime number Determination