Goldbach's Conjecture
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 36877   Accepted: 14119

Description

In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the following 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

The input will contain one or more test cases.

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

For
each test case, print one line of the form n = a + b, where a and b are
odd primes. Numbers and operators should be separated by exactly one
blank like in the sample output below. If there is more than one pair of
odd primes adding up to n, choose the pair where the difference b - a
is maximized. If there is no such pair, print a line saying "Goldbach's
conjecture is wrong."

Sample Input

8
20
42
0

Sample Output

8 = 3 + 5
20 = 3 + 17
42 = 5 + 37

Source

Ulm Local 1998
思路:筛选法弄出素数,然后a从最小素数循环,遇到结果就直接输出。注意C语言比C++速度

#include<stdio.h>
#include<math.h>
#include<string.h>
#define MAXN 1000001
bool vis[MAXN]; int main()
{
//筛选法挑选素数
memset(vis,,sizeof(vis));
for(int i = ;i<(int)sqrt((double)MAXN);i++)
{
if(!vis[i])
{
for(int j=i*i ; j<MAXN;j+=i)
vis[j]=;
}
}
int n;
while(scanf("%d",&n)!=EOF&&n!=)
{
int a = ;
for(;a<n;a+=)
{
if(!vis[(n-a)]&&!vis[a])
{
printf("%d = %d + %d\n",n,a,n-a);
break;
}
}
}
return ;
}

快些。

 

poj2262的更多相关文章

  1. poj2262 Goldbach's Conjecture

    poj2262 Goldbach's Conjecture 用欧拉筛把素数筛出来,再枚举一下. #include<iostream> #include<cstdio> #inc ...

  2. [POJ2262] Goldbach’s Conjecture

    Goldbach's Conjecture Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 48161   Accepted: ...

  3. POJ2262问题描述

    Goldbach's Conjecture   Description In 1742, Christian Goldbach, a German amateur mathematician, sen ...

  4. poj2909 || poj2262

    #include <stdio.h> #include <stdlib.h> #include<math.h> int isPri(int a, int b) { ...

  5. 筛法求质——poj2262&2909

    这两道题都是哥赫巴德猜想的内容.基本的技术点都是在一个很大的数字范围里面求质数.直接判断两个数是不是质数,这种方法虽然可行但是还是很慢的.所以这两题我们使用打表! 而建立质数表的方法就是筛法求质,速度 ...

  6. [暑假集训--数论]poj2262 Goldbach's Conjecture

    In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in whic ...

  7. poj2262 Goldbach's Conjecture——筛素数

    题目:http://poj.org/problem?id=2262 水水更健康~ 代码如下: #include<iostream> #include<cstdio> #incl ...

  8. 【转】POJ题目分类推荐 (很好很有层次感)

    OJ上的一些水题(可用来练手和增加自信) (poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094)初期: 一. ...

  9. POJ推荐50题

    此文来自北京邮电大学ACM-ICPC集训队 此50题在本博客均有代码,可以在左侧的搜索框中搜索题号查看代码. 以下是原文: POJ推荐50题1.标记“难”和“稍难”的题目可以看看,思考一下,不做要求, ...

随机推荐

  1. openstack组件手动部署整合

    preface:当你完全且正确的配置好整个OpenStack ENV 你将能看到的和体验到的!!! 我们先来看看简单效果吧,祝君能在这条路上走的更远,更好;

  2. phpcms:五、网站首页(index.html)

    1.经典案例:图文列表:{pc:content  action="position" posid="2" order="listorder DESC& ...

  3. Firefox历史版本下载

    http://ftp.mozilla.org/pub/firefox/releases/ http://ftp.mozilla.org/pub/firefox/releases/47.0.1/

  4. 如何安装CocoaPods

    转自 http://www.99css.com/1321/ 在 iOS 项目开发中,经常会用到第三方的源代码,CocoaPods 就是为了方便管理这些源码的工具. 在官方教程里面,安装看起来非常简单 ...

  5. 【Android 应用开发】 ActionBar 样式详解 -- 样式 主题 简介 Actionbar 的 icon logo 标题 菜单样式修改

    作者 : 万境绝尘 (octopus_truth@163.com) 转载请著名出处 : http://blog.csdn.net/shulianghan/article/details/3926916 ...

  6. UVa 10701 - Pre, in and post

    题目:已知树的前根序,中根序遍历转化成后根序遍历. 分析:递归,DS.依据定义递归求解就可以. 前根序:根,左子树,右子树: 中根序:左子树,根,右子树: 每次,找到根.左子树.右子树,然后分别递归左 ...

  7. ajax(ajax开发)

    AJAX即“Asynchronous Javascript And XML”(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术. AJAX = 异步 JavaScript和 ...

  8. seajs初尝 加载jquery返回null解决学习日志含示例下载

    原文地址:http://www.tuicool.com/articles/bmuaEb 如需demo示例,请点击下方链接下载: http://yunpan.cn/cVEybKs8nV7CF  提取码 ...

  9. IEquatable(T) interface in .Net

    原文:http://weblogs.asp.net/pawanmishra/iequatable-t-interface-in-net 泛型方法: public static bool AreEqua ...

  10. UVA 10790 How Many Points of Intersection?

      How Many Points of Intersection?  We have two rows. There are a dots on the top row and b dots on ...