素数判定
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 91615 Accepted Submission(s): 32165
0 1 0 0
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;
}