Twin Prime Conjecture

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Problem Description
If we define dn as: dn = pn+1-pn, where pi is the i-th prime. It is easy to see that d1 = 1 and dn=even for n>1. Twin Prime Conjecture states that "There are infinite consecutive primes differing by 2".
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
Your program must read test cases from standard 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
For each test case, your program must output to standard output. Print in one line the number of twin primes which are no greater than N.
 
Sample Input
1
5
20
-2
 
Sample Output
0
1
4
 
Source
题意:在n以内的孪生素数的对数;

思路:本以为素数打表+暴力能过,结果数据好像很多,求下前缀和打个表就行;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define pi (4*atan(1.0))
const int N=1e5+,M=1e6+,inf=1e9+;
const int MAXN=;
int prime[MAXN];
bool vis[MAXN];
int Prime(int n)
{
int cnt=;
memset(vis,,sizeof(vis));
for(int i=;i<n;i++)
{
if(!vis[i])
prime[cnt++]=i;
for(int j=;j<cnt&&i*prime[j]<n;j++)
{
vis[i*prime[j]]=;
if(i%prime[j]==)
break;
}
}
return cnt;
}
int flag[N];
int sum[N];
int main()
{
int ji=Prime(MAXN);
int x,y,z,i,t;
for(i=;i<ji;i++)
{
if(prime[i]-prime[i-]==)
flag[prime[i]]=;
}
for(i=;i<=;i++)
sum[i]=sum[i-]+flag[i];
while(~scanf("%d",&x))
{
if(x<)break;
printf("%d\n",sum[x]);
}
return ;
}

hdu 3792 Twin Prime Conjecture 前缀和+欧拉打表的更多相关文章

  1. 2011年浙大:Twin Prime Conjecture

    Twin Prime Conjecture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  2. Twin Prime Conjecture(浙大计算机研究生保研复试上机考试-2011年)

    Twin Prime Conjecture                                            Time Limit: 2000/1000 MS (Java/Othe ...

  3. 『素数 Prime判定和线性欧拉筛法 The sieve of Euler』

    素数(Prime)及判定 定义 素数又称质数,一个大于1的自然数,除了1和它自身外,不能整除其他自然数的数叫做质数,否则称为合数. 1既不是素数也不是合数. 判定 如何判定一个数是否是素数呢?显然,我 ...

  4. HDU 1286:找新朋友(欧拉函数)

    http://acm.hdu.edu.cn/showproblem.php?pid=1286 题意:中文. 思路:求欧拉函数. #include <cstdio> #include < ...

  5. POJ2909_Goldbach's Conjecture(线性欧拉筛)

    Goldbach's Conjecture: For any even number n greater than or equal to 4, there exists at least one p ...

  6. POJ 3126 Prime Path (bfs+欧拉线性素数筛)

    Description The ministers of the cabinet were quite upset by the message from the Chief of Security ...

  7. hdu 3307 Description has only two Sentences (欧拉函数+快速幂)

    Description has only two SentencesTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...

  8. HDU 6088 Rikka with Rock-paper-scissors(NTT+欧拉函数)

    题意 \(n\) 局石头剪刀布,设每局的贡献为赢的次数与输的次数之 \(\gcd\) ,求期望贡献乘以 \(3^{2n}\) ,定义若 \(xy=0\) 则,\(\gcd(x,y)=x+y\) 思路 ...

  9. HDU 4549 矩阵快速幂+快速幂+欧拉函数

    M斐波那契数列 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Sub ...

随机推荐

  1. ios获取设备手持方向——电子罗盘

    转:http://book.51cto.com/art/201411/457105.htm 2014-11-15 19:07 张亚飞/崔巍 中国铁道出版社 字号:T | T 综合评级: 想读()  在 ...

  2. 项目中启动另外的一个app

    NSMutableString *webViewContent = [[NSMutableStringalloc] init]; [webViewContent appendString:@" ...

  3. Centos6.8下搭建SVN服务器

    1.Centos6.8下搭建SVN服务器 Subversion是一个自由,开源的版本控制系统.Subversion将文件存放在中心版本库里.这个版本库很像一个普通的文件服务器,不同的是,它可以记录每一 ...

  4. CentOS 目录结构详解

     linux 目录结构 linux目录树 /: 根目录,一般根目录下只存放目录,不要存放文件,/etc./bin./dev./lib./sbin应该和根目录放置在一个分区中/bin:/usr/bin: ...

  5. supervisor 配置篇

    1,配置管理进程 进程管理配置参数,不建议全都写在supervisord.conf文件中,应该每个进程写一个配置文件放在include指定的目录下包含进supervisord.conf文件中. 1&g ...

  6. lambda 缩写推演

  7. 爬虫基础 - Robots协议

    Robots协议 指定一个robots.txt文件,告诉爬虫引擎怎么爬取 https://www.taobao.com/robots.txt User-agent: Baiduspider Allow ...

  8. 【转】sql server 订阅发布、快照发布(一)

    原文链接:https://blog.csdn.net/tiandi_5000/article/details/11646023 SQL SERVER 2012 使用订阅发布同步数据库(一) 2013年 ...

  9. 为什么Log.nsf中存储的日志只有最近7天的原因

    是由于Domino服务器的notes.ini配置文件中有一行参数: Log = logfilename, log_option, not_used, days, size 比如:Log=log.nsf ...

  10. 003-spring cache-JCache (JSR-107) annotations

    参看地址:https://docs.spring.io/spring/docs/current/spring-framework-reference/integration.html#cache-js ...