HDOJ_2012_素数判定

AC代码:

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main(void)
{
    //freopen("in.txt","r",stdin);
    int x,y;
    while((scanf("%d%d",&x,&y)!=EOF)&&(x||y))
    {
        int count=1;
        for(int i=x; i<=y; i++)
        {
            int k=i*i+i+41, j;
            for(j=2;j<=sqrt(k);j++)
            {
                if(k%j==0)
                    break;
            }
            if(j<=sqrt(k))
            {
                count=0;
                break;
            }    
        }
        if(count==0)
            printf("Sorry\n");
        else
            printf("OK\n");
    }
    
    //fclose(stdin);
    return 0;
} 

猜你喜欢

转载自www.cnblogs.com/phaLQ/p/9941339.html