UVA10394 Twin Primes【孪生素数】
Twin primes are pairs of primes of the form (p, p + 2). The term “twin prime” was coined by Paul Stckel (1892-1919). The first few twin primes are (3, 5), (5, 7), (11, 13), (17, 19), (29, 31), (41, 43). In this problem you are asked to find out the S-th twin prime pair where S is an integer that will be given in the input.
Input
The input will contain less than 10001 lines of input. Each line contains an integers S (1 ≤ S ≤ 100000), which is the serial number of a twin prime pair. Input file is terminated by end of file.
Output
For each line of input you will have to produce one line of output which contains the S-th twin prime pair. The pair is printed in the form (p1,¡space¿p2). Here ¡space¿ means the space character (ASCII 32) . You can safely assume that the primes in the 100000-th twin prime pair are less than 20000000.
Sample Input
1
2
3
4
Sample Output
(3, 5)
(5, 7)
(11, 13)
(17, 19)
问题链接:UVA10394 Twin Primes
问题简述:(略)
问题分析:
孪生素数问题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的C++语言程序如下:
/* UVA10394 Twin Primes */#include <bits/stdc++.h>using namespace std;const int N = 20000000;
bool isprime[N + 1];
int prime[N / 3], pcnt = 0, twprime[N / 9], twcnt = 1;
// 欧拉筛
void eulersieve(void)
{memset(isprime, true, sizeof(isprime));isprime[0] = isprime[1] = false;for(int i = 2; i <= N; i++) {if(isprime[i])prime[pcnt++] = i;for(int j = 0; j < pcnt && i * prime[j] <= N; j++) { //筛选isprime[i * prime[j]] = false;if(i % prime[j] == 0) break;}}prime[pcnt] = 0;for(int i = 0; i < pcnt; i++)if(prime[i] + 2 == prime[i + 1]) twprime[twcnt++] = prime[i];}int main()
{eulersieve();int n;while(~scanf("%d", &n))printf("(%d, %d)\n", twprime[n], twprime[n] + 2);return 0;
}
UVA10394 Twin Primes【孪生素数】相关推荐
- Competitive Programming 3题解
题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...
- 张益唐的孪生素数证明
张益唐的孪生素数证明 文章目录 张益唐的孪生素数证明 前言 第一章:孪生素数的历史与问题 第二章:张益唐的思路与方法 张益唐的孪生素数证明过程 第三章:张益唐的贡献与成果 第四章:孪生素数的意义和影响 ...
- UVa 10394-Twin Primes
2019独角兽企业重金招聘Python工程师标准>>> [问题描述] Twin primes are pairs of primes of the form (p, p+2). Th ...
- Extended Twin Composite Number 思维题
Do you know the twin prime conjecture? Two primes a and b are called twin primes if a+2=b. The twin ...
- 判断是否为质数的超级优化 C++语言(超详细)
首先我们要知道质数的概念: 质数(prime number)又称素数,有无限个.质数定义为在大于1的自然数中,除了1和它本身以外不再有其他因数. 知道了质数的概念,我们就可以大胆的说:"老师 ...
- 求质数(Prime Number 素数)的方法——厄拉多塞筛法
质数又称素数.指在一个大于1的自然数中,除了1和此整数自身外,没法被其他自然数整除的数.换句话说,只有两个正因数(1和自己)的自然数即为素数.比1大但不是素数的数称为合数.1和0既非素数也非合数.合数 ...
- 陈景润学术地位无人可及
陈景润学术地位无人可及 本文附件是筛法英文维基的的原文.文中作者把陈景润1+2定理看做是哥德巴赫与孪生素数两个猜想的"近乎无误"(near-misses)的数学证明,陈景润的学术地 ...
- 计算机解题报告,计算机题目33题(附带题解)精选.doc
第1~10题为基础题,第11~20题为提高题,第21~33为综合题 每位同学分别从基础题.提高题.综合题中各选一题,按学号顺序循环选择,用word写报告.每班评出优秀的9名同学,上台做报告,每人期末成 ...
- π-Algorithmist分类题目(1)
原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(1) Sorting UVAL ...
最新文章
- Kubernetes源码阅读笔记——Controller Manager(之三)
- 一篇文章教你弄懂 SpringMvc中的HandlerInterceptor
- push方法java_万字长文深入浅出谈Java数据类型系列之Stack
- PHP的getimagesize获取图像信息
- nginx 修改配置文件使之支持pathinfo,且隐藏index.php
- java异常—— finally 子句+带资源的 try语句
- 快速提示:使用Chrome开发工具调试GWT应用程序
- CM3计算板I/O编程
- 安卓mysql修改_手动修改Android数据库数据
- sql server 用户创建与权限管理
- python机器学习-糖尿病数据挖掘
- 计网实验三 虚拟局域网 VLAN
- win10磁盘分区时无法删除卷解决办法
- tensorflow量化感知训练_TensorFlow 8 bit模型量化
- 序列化器serializers的使用
- 理解Java并发编程:CountDownLatch解析
- DNSpod+安全宝+360网站卫士的双CDN加速服务
- chart.js画图
- VII python(1)基础知识
- mdpi的手机_APP设计尺寸