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 }

 

转载于:https://www.cnblogs.com/BBBob/p/6641679.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值