hdu2012

http://acm.hdu.edu.cn/showproblem.php?pid=2012

数组大小算错了。。。。。郁闷-_-

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<stdlib.h>
 4 #include<string.h>
 5 #include<math.h>
 6 using namespace std;
 7 const int N=2600;
 8 int prime[N];
 9 void isprime()
10 {
11     memset(prime,0,sizeof(prime));
12     prime[0]=1;
13     prime[1]=1;
14     for(int i=2;i<N;i++)
15     {
16         if(!prime[i])
17         {
18             for(int j=i+i;j<N;j+=i)
19             prime[j]=1;
20         }
21     }
22     return ;
23 }
24 
25 int main()
26 {
27     //freopen("in.txt","r",stdin);
28     int x,y;
29     isprime();
30     while(cin>>x>>y)
31     {
32         if(!x&&!y)
33         break;
34         int t;
35         if(x>y)
36         {
37             t=x;
38             x=y;
39             y=t;
40         }
41         int flag=0;
42         for(int i=x;i<=y;i++)
43         {
44             t=i*i+i+41;
45             if(prime[t])
46             {
47                 flag=1;
48                 break;
49             }
50         }
51         if(!flag)
52         cout<<"OK"<<endl;
53         else
54         cout<<"Sorry"<<endl;
55     }
56     return 0;
57 }

 

posted @ 2015-05-11 19:47  煎饼馃子  阅读(166)  评论(0编辑  收藏  举报