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;
} 

 

posted @ 2018-11-11 08:59  pha创噬  阅读(120)  评论(0编辑  收藏  举报