HDU2161 Primes

 1 /*
 2  HDU2161 Primes
 3  http://acm.hdu.edu.cn/showproblem.php?pid=2161
 4  数论 水题
 5  注意输入截止条件是n<=0
 6  */
 7 #include <cstdio>
 8 #include <algorithm>
 9 #include <cstring>
10 #include <cmath>
11 #include <vector>
12 #include <queue>
13 //#define test
14 using namespace std;
15 const int Nmax=16005;
16 int is_prime[Nmax];
17 void get()
18 {
19     for(int i=2;i<Nmax;i++)
20         is_prime[i]=1;
21     for(int i=2;i<Nmax;i++)
22     {
23         if(is_prime[i])
24         {
25             for(int j=2;j*i<Nmax;j++)
26                 is_prime[i*j]=0;
27         }
28     }
29     is_prime[2]=0;
30 }
31 int main()
32 {
33     #ifdef test
34     #endif
35     int n,t=0;
36     get();
37     while(scanf("%d",&n)==1)
38     {
39         if(n<=0)
40             break;
41         t++;
42         printf("%d: ",t);
43         if(is_prime[n])
44             printf("yes\n");
45         else
46             printf("no\n");
47     }
48  
49     return 0;
50 }

 

posted @ 2017-03-29 20:46  BBBob  阅读(203)  评论(0编辑  收藏  举报