[暑假集训--数论]poj2262 Goldbach's Conjecture
Every even number greater than 4 can be
written as the sum of two odd prime numbers.
For example:
8 = 3 + 5. Both 3 and 5 are odd prime numbers.
20 = 3 + 17 = 7 + 13.
42 = 5 + 37 = 11 + 31 = 13 + 29 = 19 + 23.
Today it is still unproven whether the conjecture is right. (Oh wait, I have the proof of course, but it is too long to write it on the margin of this page.)
Anyway, your task is now to verify Goldbach's conjecture for all even numbers less than a million.
Input
Each test case consists of one even integer n with 6 <= n < 1000000.
Input will be terminated by a value of 0 for n.
Output
Sample Input
- 8
- 20
- 42
- 0
Sample Output
- 8 = 3 + 5
- 20 = 3 + 17
- 42 = 5 + 37
把n>=6分成两个奇质数之和,小的那个要尽量小
直接暴力
- #include<cstdio>
- #include<iostream>
- #include<cstring>
- #define LL long long
- using namespace std;
- inline LL read()
- {
- LL x=,f=;char ch=getchar();
- while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
- while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
- return x*f;
- }
- int n;
- bool mk[];
- int p[],len;
- inline void getp()
- {
- for (int i=;i<=;i++)
- {
- if (!mk[i])
- {
- p[++len]=i;
- for (int j=*i;j<=;j+=i)mk[j]=;
- }
- }
- }
- int main()
- {
- getp();
- while (~scanf("%d",&n)&&n)
- {
- if (n&||n<){puts("Goldbach's conjecture is wrong.");continue;}
- for (int i=;p[i]*<=n;i++)
- if (!mk[n-p[i]]){printf("%d = %d + %d\n",n,p[i],n-p[i]);break;}
- }
- }
poj 2262
[暑假集训--数论]poj2262 Goldbach's Conjecture的更多相关文章
- [暑假集训--数论]poj2909 Goldbach's Conjecture
For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 ...
- poj2262 Goldbach's Conjecture
poj2262 Goldbach's Conjecture 用欧拉筛把素数筛出来,再枚举一下. #include<iostream> #include<cstdio> #inc ...
- [POJ2262] Goldbach’s Conjecture
Goldbach's Conjecture Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 48161 Accepted: ...
- [暑假集训--数论]hdu2136 Largest prime factor
Everybody knows any number can be combined by the prime number. Now, your task is telling me what po ...
- [暑假集训--数论]hdu1019 Least Common Multiple
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which ...
- [暑假集训--数论]poj2115 C Looooops
A Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != ...
- [暑假集训--数论]poj1365 Prime Land
Everybody in the Prime Land is using a prime base number system. In this system, each positive integ ...
- [暑假集训--数论]poj2034 Anti-prime Sequences
Given a sequence of consecutive integers n,n+1,n+2,...,m, an anti-prime sequence is a rearrangement ...
- [暑假集训--数论]poj1595 Prime Cuts
A prime number is a counting number (1, 2, 3, ...) that is evenly divisible only by 1 and itself. In ...
随机推荐
- Oracle11g 主机身份证明问题
oracle 11g的web database control中,进行一些操作需要主机身份证明,比如进行数据备份.数据的导出导入等;这样对于数据库的安全增强了一定的保证.如果我们有进行适当的配置,可以 ...
- let和const在es6中的异同点
let和const这两个都是声明一个变量或函数的方法与var差不太多的效果 let的声明在for循环中,当你定义的是多少,最后你的值就是多少开始的,它只进行一次循环,不会像var那样去一遍一遍的去遍历 ...
- 51nod——1285 山峰和分段(暴力出奇迹)
要求每段的点数都一样,因此分的段数cnt肯定是n的因子,要求每段都有山峰,因此cnt肯定小于等于山峰数量.分段的宽度d=n/cnt,对山峰数量做一个前缀和,检查一下每一段的山峰数量是否没有增加即可. ...
- UNIX网络通信
一.网络协议 国际标准化组织(ISO)定义了网络协议的基本框架,被称为OSI模型.OSI模型包括应用层.表示层.会话层.传输层.网络层.数据链路层及物理层.而OSI模型过于复杂至今没有得到实际的应用. ...
- Python_列表、字典、字符串、集合操作
一.list Python内置的一种数据类型是列表:list.list是一种有序的集合,可以随时添加和删除其中的元素.对于list的操作,我们要学会增删改查. 查 我们可以直接索引查找,也可以通过切片 ...
- Python 正则表达式 利用括号分组
如果想把区号从匹配的电话号码中分离,可以添加括号在正则表达式中创建分组,再使用group()方法,从一个分组中获取匹配的文本 正则表达式字符串中,第一个括号是第一组,第二个括号是第二组.向group( ...
- 跨域问题和django中实现跨域
跨域问题 1.同源策略(浏览器的安全功能): 请求的url地址,必须与浏览器上的url地址处于同域上,也就是域名,端口,协议相同 2.CORS跨域资源共享 实现CORS通信的关键是服务器,只要服务器实 ...
- Artwork 18年中南多校第一场A
一.题意 对于一个矩阵,若干道命令,每道命令将会把某一段格子涂黑,请问每次涂黑之后矩阵中未被涂黑的块的数量? 二.思路 保存每道命令,并且忠实的执行他,到最后一步开始搜索联通块的数量,并将其保存. 之 ...
- IntentService和Service执行子线程对比
1.为何要用子程序 服务是在主线程中执行的,直接在服务中执行耗时操作明显不可取,于是安卓官方增加了IntentService类来方便使用 在Service中执行子程序代码如下 @Override pu ...
- Java面向对象---抽象类与接口
final关键字 1.final关键字在java中被称为完结器,表示最终的意思: 2.final能声明类.方法.属性: 3.使用final声明的类不能被继承,使用final声明的方法不能被重写,使用f ...