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 ...
随机推荐
- 关于java的自增问题
程序执行结果是0,,,因为count永远是0
- gitlab系列详解
虚拟机的安装1.安装virtualboxhttps://www.virtualbox.org/2.安装centos6.63.配置网络右键-->网络-->网卡2-->host-only ...
- Vue之Vue-touch的使用
最近项目中,有的页面发现设置返回键看起来怪怪的,感觉与整体不协调,于是就考虑使用手势滑动事件来实现返回功能~ 开叉查阅资料~找到了vue-touch,使用起来可谓是简单粗暴啊,适合我这样的快速开发人员 ...
- 开启PHP-LDAP
LDAP简介: LDAP(Lightweight Directory Access Protocol)的意思是"轻量级目录访问协议",是一个用于访问"目录服务器" ...
- 【转】Mysql查询语句优化策略
1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中使用!=或<>操作符,否则将引擎放弃使用索 ...
- java util - base64转换工具
测试代码 package cn.java.codec.base64; public class Test { public static void main(String[] args) { Stri ...
- GoF23种设计模式之创建型模式之工厂方法模式
一.概述 定义一个用于创建对象的接口,让子类去决定实例化哪个类.工厂方法将一个类的实例化延迟至其子类. 二.适用性 1.当一个类不知道它所必须创建的对象的类的时候. 2.当一个类希望由其子类来指定它所 ...
- Codeforces Round #464 (Div. 2) D. Love Rescue
D. Love Rescue time limit per test2 seconds memory limit per test256 megabytes Problem Description V ...
- [Hdu3652]B-number(数位DP)
Description 题目大意:求小于n是13的倍数且含有'13'的数的个数. (1 <= n <= 1000000000) Solution 数位DP,题目需要包含13,且被13整除, ...
- poj 23565-Find a multiple
Find a multiple The input contains N natural (i.e. positive integer) numbers ( N <= 10000 ). Each ...