Primes (素数筛法)
来源:互联网 发布:网络暴力案例分析 编辑:程序博客网 时间:2024/06/17 18:15
题目来源:https://vjudge.net/problem/HDU-2161
【题意】
判断一个数是否为素数,特别的,题中认为2不是素数。
【思路】
一般的素数筛法进行完之后,在后面加一句赋值语句:vis[2]=1。代表2不是素数。
【代码】
#include<map>#include<stack>#include<queue>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>#include<iostream>#include<string>#define mem(a,b) memset(a,b,sizeof(a))#define MAXN 4000010using namespace std;const int INF=1e9;typedef long long LL;const int maxn=16010;bool vis[maxn];int main(){ int n,cases=1; for(int i=2;i<=maxn;i++) { if(!vis[i]) { for(int j=i*2;j<=maxn;j+=i) { vis[j]=1; } } } vis[2]=1,vis[1]=1; while(~scanf("%d",&n)) { if(n<=0) break; if(vis[n]) printf("%d: no\n",cases++); else printf("%d: yes\n",cases++); }}
0 0
- Primes (素数筛法)
- HDU5104 Primes Problem(素数筛选法)
- Primes(素数)
- CodeForce 237C Primes on Interval(二分+ 素数筛法)
- leetcode---Count Primes---素数筛法的改进
- Count Primes 筛选法求素数
- HDOJ 2161 Primes (判断素数)
- HDU 2161 Primes(素数打表)
- Primes Problem (HDU5104) 素数问题
- LeetCode 204. Count Primes(统计素数)
- hdu 5104 Primes Problem(素数判定)
- (LeetCode)Count Primes --- 统计素数(质数)
- 【HDU5901】Count primes(大素数模板)
- 【HDU 2161】Primes(素数~水)
- 204. Count Primes (素数筛选)
- LeetCode--Count Primes(素数个数)Python
- hdu 4715 Difference Between Primes【筛法快速求素数表+思维】
- PAT (Advanced Level) Practise 1015. Reversible Primes (20) 素数筛法 进制转换
- oracle数据库怎么创建新用户
- 了解自己
- http://blog.csdn.net/jdsjlzx/article/details/53186564
- Unhandled event loop exception No more handles问题解决记录
- C/C++_log2000_windows编程之第一个控制台程序项目part1
- Primes (素数筛法)
- 解决ActivityNotFoundException: No Activity found to handle Intent
- CRC基本原理
- Linux基本命令2
- ThreadLocal、volatile、synchronized、Atomic关键字
- Data Types
- zabbix监控Nginx状态
- 分布式架构学习之:000--介绍Dubbo
- Python装饰器学习(九步入门)