HDU 3792 素数打表
Description
Now given any positive integer N (< 10^5), you are supposed to count the number of twin primes which are no greater than N.
Input
The input file consists of several test cases. Each case occupies a line which contains one integer N. The input is finished by a negative N.
Output
Sample Input
Sample Output
#include<bits/stdc++.h>
#define ll __int64
#define mod 1e9+7
#define PI acos(-1.0)
#define bug(x) printf("%%%%%%%%%%%%%",x);
#define inf 1e8
using namespace std;
int n;
bool visit[];
int prime[];
int ans[];
void fun()
{
memset(visit, true, sizeof(visit));
int num = ;
visit[]=false;
for (int i = ; i <= ; ++i)
{
if (visit[i] == true)
{
num++;
prime[num]=i;
//mp[i]=num;
}
for (int j=;((j<=num)&&(i*prime[j]<= ));++j)
{
visit[i*prime[j]] =false;
if (i%prime[j]==)break; //点睛之笔
}
}
int jishu=;
for(int i=;i<=;i++)
{
if(visit[i]&&visit[i-])
jishu++;
ans[i]=jishu;
}
ans[]=;
ans[]=;
ans[]=;
}
int main()
{
fun();
while(scanf("%d",&n)!=EOF)
{
if(n<)
break;
printf("%d\n",ans[n]);
}
return ;
}
HDU 3792 素数打表的更多相关文章
- hdu 5104 素数打表水题
http://acm.hdu.edu.cn/showproblem.php?pid=5104 找元组数量,满足p1<=p2<=p3且p1+p2+p3=n且都是素数 不用素数打表都能过,数据 ...
- HDU 2136 素数打表+求质数因子
Largest prime factor Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 1397 Goldbach's Conjecture【素数打表】
题意:给出n,问满足a+b=n且a,b都为素数的有多少对 将素数打表,再枚举 #include<iostream> #include<cstdio> #include<c ...
- hdu 3792 Twin Prime Conjecture 前缀和+欧拉打表
Twin Prime Conjecture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- Codeforces Round #315 (Div. 2C) 568A Primes or Palindromes? 素数打表+暴力
题目:Click here 题意:π(n)表示不大于n的素数个数,rub(n)表示不大于n的回文数个数,求最大n,满足π(n) ≤ A·rub(n).A=p/q; 分析:由于这个题A是给定范围的,所以 ...
- CodeForces 385C Bear and Prime Numbers 素数打表
第一眼看这道题目的时候觉得可能会很难也看不太懂,但是看了给出的Hint之后思路就十分清晰了 Consider the first sample. Overall, the first sample h ...
- LightOJ 1259 Goldbach`s Conjecture 素数打表
题目大意:求讲一个整数n分解为两个素数的方案数. 题目思路:素数打表,后遍历 1-n/2,寻找方案数,需要注意的是:C/C++中 bool类型占用一个字节,int类型占用4个字节,在素数打表中采用bo ...
- hdu 1496 Equations hash表
hdu 1496 Equations hash表 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1496 思路: hash表,将原来\(n^{4}\)降 ...
- [ACM] POJ 2635 The Embarrassed Cryptographer (同余定理,素数打表)
The Embarrassed Cryptographer Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11978 A ...
随机推荐
- oc不可变数组创建
//创建数组 //1.快速创建数组 @[] NSArray *week=@[@"MON",@"TUE",@"WED",@"THU ...
- HTML <input> 标签如何屏蔽浏览器的自动填写?
autocomplete = "off",实测无效. <input type="text" autocomplete = "off"/ ...
- vue 采坑
1.ref 在父组件中访问子组件实例,或者直接操作DOM元素时需要ref <input ref="ipt"> 通过this.$refs.ipt 得到此input $re ...
- 学习笔记(六): Regularization for Simplicity
目录 Overcrossing? L₂ Regularization Lambda Examining L2 regularization Check Understanding Glossay Ov ...
- 2018.11.7 Nescafe29 T1 穿越七色虹
题目 题目背景 在 Nescafe27 和 28 中,讲述了一支探险队前往 Nescafe 之塔探险的故事…… 当两位探险队员以最快的时间把礼物放到每个木箱里之后,精灵们变身为一缕缕金带似的光,簇簇光 ...
- centos7上基于kubernetes的docker集群管理
kubernetes和docker的作用这里就不作介绍了,直接进入主题. 本文的目的是搭建docker集群,并使用kubernetes管理它们. 文中的软件环境除了kubernetes和docker, ...
- python---列表(list)基本操作
列表基本操作:增.删.查.改等其他操作 创建列表: list1 = ["a","b","c","d"] name_lis ...
- L1-049 天梯赛座位分配 (20 分)
天梯赛每年有大量参赛队员,要保证同一所学校的所有队员都不能相邻,分配座位就成为一件比较麻烦的事情.为此我们制定如下策略:假设某赛场有 N 所学校参赛,第 i 所学校有 M[i] 支队伍,每队 10 位 ...
- python并发编程相关概念总结
1.简述计算机操作系统中的“中断”的作用? 中断是指在计算机执行期间,系统内发生任何非寻常的或非预期的急需处理事件,使得CPU暂时中断当前正在执行的程序而转去执行相应的时间处理程序.待处理完毕后又返回 ...
- P3398 仓鼠找sugar(树链剖分)
P3398 仓鼠找sugar 题目描述 小仓鼠的和他的基(mei)友(zi)sugar住在地下洞穴中,每个节点的编号为1~n.地下洞穴是一个树形结构.这一天小仓鼠打算从从他的卧室(a)到餐厅(b),而 ...