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

HDU2161 Primes相关推荐

  1. PAT甲级1015 Reversible Primes :[C++题解]进制位、秦九韶算法、判质数

    文章目录 题目分析 题目链接 题目分析 十进制转化为d进制如何做? while(n){n% d; //取d进制数下的最低位n/=d; } 比如 十进制下的n=13 ,进制d =2.经过 反复的n%d ...

  2. CodeForce 237C Primes on Interval(二分+ 素数筛法)

    题目链接:http://codeforces.com/problemset/problem/237/C Primes on Interval time limit per test 1 second ...

  3. 204. Count Primes

    Count the number of prime numbers less than a non-negative number, n. Example: Input: 10 Output: 4 E ...

  4. CodeCraft-20 (Div. 2) C. Primitive Primes 思维 + 数论

    传送门 文章目录 题意: 思路: 题意: 给你两个长度分别为n,mn,mn,m的多项式,将他们乘起来,问系数modp=0\bmod p =0modp=0的项的指数是多少,两个多项式所有项的系数gcd= ...

  5. 【CodeForces - 1150C】Prefix Sum Primes(思维)

    题干: We're giving away nice huge bags containing number tiles! A bag we want to present to you contai ...

  6. 【CodeForces - 569C】Primes or Palindromes? (思维,分析范围,暴力枚举判断)

    题干: Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are ...

  7. Leetcode-204 Count Primes

    #204 Count Primes Count the number of prime numbers less than a non-negative number, n. 题解:这道题如果对每个小 ...

  8. leetCode 204. Count Primes 哈希 求素数

    204. Count Primes 求素数 Description: Count the number of prime numbers less than a non-negative number ...

  9. UVa 10394-Twin Primes

    2019独角兽企业重金招聘Python工程师标准>>> [问题描述] Twin primes are pairs of primes of the form (p, p+2). Th ...

最新文章

  1. jieba分词工具的使用方法
  2. MySQL删库数据延迟恢复策略
  3. Object-C中的字符串对象1-不可变字符串
  4. php接受post接受不到数据,PHP $_POST接受不到数据,但$_GET可以接受数据
  5. Linux-磁盘及网络IO工作方式解析
  6. 计算机安全知识讲座,计算机学院安全知识讲座:防火防电防诈骗 人身安全记心间...
  7. leetcode 两个排序的中位数 python
  8. PHP学习笔记--函数
  9. Oracle如何选择合适的列作为索引?
  10. 语音文件aac-raw-wav格式转换方法
  11. 印度it公司_2016年印度十大IT公司
  12. python web微信应用(六) 监测微信撤回的消息
  13. oracle试题和答案,Oracle面试题及答案
  14. 实时操作系统和非实时操作系统的区别
  15. Android 自定义桌面(一)
  16. 浪潮信息m6服务器性能,M6四路服务器——浪潮信息新品性能显著
  17. CAKEPHP 常见错误
  18. 嵌入式软件工程师 面试题 (持续更新中)
  19. 2018计算机网络原理自考4月,2018年4月自考计算机网络原理04741试题及答案
  20. css布局作业:京东首页轮播图

热门文章

  1. ubuntu 安装php mcrypt扩展
  2. VC----SDK下对窗口非客户区的操作
  3. [原创]聊聊如何在职场中发邮件
  4. JavaScript学习(九十二)—关联数组的基本操作
  5. 线程的五大状态及转换
  6. 理财产品利息一直降低是什么原因?
  7. 长痘痘了吃什么好得快?
  8. 如果你想自己创业,做社区超市
  9. 为什么越来越多的人尝试做自媒体
  10. 找出消费者在使用你的产品的时候,什么时刻觉得“值了”