[暑假集训--数论]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 ...
随机推荐
- DOS当中的基本操作命令,如何切换磁盘,如何查看文件和文件夹,如何清屏,进入文件夹的命令,javac是什么意思,作用是什么?DOS如何建文件夹?退出文件夹?
如何切换磁盘:使用盘符+:举例 d: 如何查看文件和文件夹 dir/w 如何清屏: cls (clear screen) 进入文件夹的命令cd ,举例cd JDK javac是什么意思,c 是comp ...
- Linux Shell 几个特殊符号命令 & 、&& 、 ||
& 放在启动参数后面表示设置此进程为后台进程 默认情况下,进程是前台进程,这时就把Shell给占据了,我们无法进行其他操作,对于那些没有交互的进程,很多时候,我们希望将其在后台启动,可以在启动 ...
- MongDB之各种新增操作
接口IMongDaoCreate: package com.net.test.mongdb.dao; import java.util.List; import com.net.test.mongdb ...
- Leetcode 106. 从中序与后序遍历序列构造二叉树
题目链接 https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/descri ...
- momo不是玩具,.Net雄起
互联网时代 .NET 会渐渐衰落吗?一个架构师对 .NET 的思考 2015-12-14 11:03 darklx 博客园 字号:T | T 为了更好的适应互联网时代的需求,我们公司已经把我们的 .N ...
- python单元测试用例
demo1.py #!/usr/bin/python # encoding: utf-8 def hello(): print "i am in demo1" def add(x, ...
- vue2.x生命周期
vue2.x生命周期 1. beforeCreate 在实例初始化之后,数据观测(data observer) 和 event/watcher 事件配置之前被调用. 2. created 实例已经创建 ...
- MFC深入浅出读书笔记第二部分1
第六章 MFC程序的生死因果 MFC学习过程,这个方法不错,条例清晰. 1.CWinApp -- 取代WinMain地位 WinMain函数的功能由CWinApp的三个函数实现 virtual BO ...
- python2.7运行报警告:UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal解决办法
1. 程序源代码报错部分: #选择年级if grade == '幼升小': outline.nianji().pop(0).click()elif grade == "一年级": ...
- sql注入语句大全
sql注入语句大全--是否存在xp_cmdshell and 1=(select count(*) from master.dbo.sysobjects where xtype = 'x' and n ...