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
HDU2161 Primes相关推荐
- PAT甲级1015 Reversible Primes :[C++题解]进制位、秦九韶算法、判质数
文章目录 题目分析 题目链接 题目分析 十进制转化为d进制如何做? while(n){n% d; //取d进制数下的最低位n/=d; } 比如 十进制下的n=13 ,进制d =2.经过 反复的n%d ...
- CodeForce 237C Primes on Interval(二分+ 素数筛法)
题目链接:http://codeforces.com/problemset/problem/237/C Primes on Interval time limit per test 1 second ...
- 204. Count Primes
Count the number of prime numbers less than a non-negative number, n. Example: Input: 10 Output: 4 E ...
- CodeCraft-20 (Div. 2) C. Primitive Primes 思维 + 数论
传送门 文章目录 题意: 思路: 题意: 给你两个长度分别为n,mn,mn,m的多项式,将他们乘起来,问系数modp=0\bmod p =0modp=0的项的指数是多少,两个多项式所有项的系数gcd= ...
- 【CodeForces - 1150C】Prefix Sum Primes(思维)
题干: We're giving away nice huge bags containing number tiles! A bag we want to present to you contai ...
- 【CodeForces - 569C】Primes or Palindromes? (思维,分析范围,暴力枚举判断)
题干: Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are ...
- Leetcode-204 Count Primes
#204 Count Primes Count the number of prime numbers less than a non-negative number, n. 题解:这道题如果对每个小 ...
- leetCode 204. Count Primes 哈希 求素数
204. Count Primes 求素数 Description: Count the number of prime numbers less than a non-negative number ...
- UVa 10394-Twin Primes
2019独角兽企业重金招聘Python工程师标准>>> [问题描述] Twin primes are pairs of primes of the form (p, p+2). Th ...
最新文章
- jieba分词工具的使用方法
- MySQL删库数据延迟恢复策略
- Object-C中的字符串对象1-不可变字符串
- php接受post接受不到数据,PHP $_POST接受不到数据,但$_GET可以接受数据
- Linux-磁盘及网络IO工作方式解析
- 计算机安全知识讲座,计算机学院安全知识讲座:防火防电防诈骗 人身安全记心间...
- leetcode 两个排序的中位数 python
- PHP学习笔记--函数
- Oracle如何选择合适的列作为索引?
- 语音文件aac-raw-wav格式转换方法
- 印度it公司_2016年印度十大IT公司
- python web微信应用(六) 监测微信撤回的消息
- oracle试题和答案,Oracle面试题及答案
- 实时操作系统和非实时操作系统的区别
- Android 自定义桌面(一)
- 浪潮信息m6服务器性能,M6四路服务器——浪潮信息新品性能显著
- CAKEPHP 常见错误
- 嵌入式软件工程师 面试题 (持续更新中)
- 2018计算机网络原理自考4月,2018年4月自考计算机网络原理04741试题及答案
- css布局作业:京东首页轮播图