HDU 2161 Primes (素数筛选法)
题意:输入一个数判断是不是素数,并规定2不是素数。
析:一看就很简单吧,用素数筛选法,注意的是结束条件是n<0,一开始被坑了。。。
不说了,直接上代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath> using namespace std;
typedef long long LL;
const int maxn = 16000 + 10;
int prime[maxn]; void init(){
memset(prime, 0, sizeof(prime));
for(int i = 2; i < sqrt(maxn+0.5); ++i) if(!prime[i])
for(int j = i * i; j < maxn; j += i)
if(!prime[j]) prime[j] = 1;
} int main(){
init();
int n, kase = 1;;
while(scanf("%d", &n), n > 0){
printf("%d: ", kase++);
if(1 == n || 2 == n || prime[n]) puts("no");
else puts("yes"); }
return 0;
}
HDU 2161 Primes (素数筛选法)的更多相关文章
- HDOJ(HDU) 2161 Primes(素数打表)
Problem Description Write a program to read in a list of integers and determine whether or not each ...
- 数学--数论--HDU 2136(素数筛选法)
Everybody knows any number can be combined by the prime number. Now, your task is telling me what po ...
- POJ 3978 Primes(素数筛选法)
题目 简单的计算A,B之间有多少个素数 只是测试数据有是负的 //AC //A和B之间有多少个素数 //数据可能有负的!!! #include<string.h> #include< ...
- POJ 2689 Prime Distance (素数筛选法,大区间筛选)
题意:给出一个区间[L,U],找出区间里相邻的距离最近的两个素数和距离最远的两个素数. 用素数筛选法.所有小于U的数,如果是合数,必定是某个因子(2到sqrt(U)间的素数)的倍数.由于sqrt(U) ...
- poj 2262 Goldbach's Conjecture(素数筛选法)
http://poj.org/problem?id=2262 Goldbach's Conjecture Time Limit: 1000MS Memory Limit: 65536K Total ...
- LightOJ 1259 Goldbach`s Conjecture (哥德巴赫猜想 + 素数筛选法)
http://lightoj.com/volume_showproblem.php?problem=1259 题目大意:给你一个数n,这个数能分成两个素数a.b,n = a + b且a<=b,问 ...
- HDU_2136——最大质因数,素数筛选法
Problem Description Everybody knows any number can be combined by the prime number. Now, your task i ...
- 51nod 1536不一样的猜数游戏 思路:O(n)素数筛选法。同Codeforces 576A Vasya and Petya's Game。
废话不多说,先上题目. 51nod Codeforces 两个其实是一个意思,看51nod题目就讲的很清楚了,题意不再赘述. 直接讲我的分析过程:刚开始拿到手有点蒙蔽,看起来很难,然后......然后 ...
- PAT甲题题解-1059. Prime Factors (25)-素数筛选法
用素数筛选法即可. 范围long int,其实大小范围和int一样,一开始以为是指long long,想这就麻烦了该怎么弄. 而现在其实就是int的范围,那难度档次就不一样了,瞬间变成水题一枚,因为i ...
随机推荐
- as2 fla 关于影片在时间轴的问题
多帧上面放着没实例名而且里面内容一致的影片,主要一开始读取了,那么跳帧的时候.会自动获取当前帧上的相同内容的影片. 但如果内容不一致的影片,那么在跳帧后,不会获取当前的影片,旧的影片也无法获取.只在当 ...
- css兼容性记录
* , ie6,ie7可以识别: _和- , ie6可以识别: !important ,表示高优先级,ie7及以上,firefox都支持,ie6认识带!important的样式属性, ...
- fasta/fastq格式解读
1)知识简介--------------------------------------------------------1.1)测序质量值 首先在了解fastq,fasta之前,了解一下什么是质量 ...
- MyBatis 通用Mapper接口 Example的实例
一.mapper接口中的方法解析 mapper接口中的函数及方法 方法 功能说明 int countByExample(UserExample example) thorws SQLException ...
- IE低版本浏览器兼容问题
head标签中填写如下代码 <meta name="renderer" content="webkit"/> <meta name=" ...
- Request method 'GET' not supported
Request method 'GET' not supported 错误原因: GET请求不被允许. 解决方法: 1.从客户端入手.假设浏览器中的js用了ajax发起异步请求GET,将GET改为PO ...
- 第五章 二叉树(e1)先序遍历
- 通过阿里OSS文件服务返回的URL获取文件流下载
我们都知道将文件上传到阿里的OSS文件服务上后,可以通过generatePresignedUrl(bucketName, key, expiration)方法获取该文件的防问路径,但是当我们知道该文件 ...
- Hammer.js——给bootstrap添加触屏功能
Hammer.js qq群号(html5技术交流):158677025 手机端演示二维码(或直接在手机中输入网址:http://lilinfeng.cncoder.me 浏览效果): 一.前言 移 ...
- sqlserver 几种datatime的区别
参考文章1 smalldatetime 占4位精确到分钟.时间从1900.1.1到2079.6.6datetime占8位精确到毫秒.时间从1753.1.1到9999.12.31 参考文章2 datet ...