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. 上传图片代码(chuantouxiang.php+touxiangchuli.php)

    <body> <form action="touxiangchuli.php" method="post" enctype="mul ...

  2. zoj 3706 Break Standard Weight(dp)

    Break Standard Weight Time Limit: 2 Seconds                                     Memory Limit: 65536 ...

  3. MVC MVC 路由详解

    在项目中我们引用了System.Web.Routing;   Routing的作用: 确定Controller 确定Action 确定其他参数 根据识别出来的数据, 将请求传递给Controller和 ...

  4. Highcharts 点击反选

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  5. [Javascript] How to use JavaScript's String.replace

    In JavaScript, you can change the content of a string using the replace method. This method signatur ...

  6. js jsp 时间 日期 控件 插件 简单 实用

    js时间控件一般都是找网上的用,这东西平常很少涉及到,一用到找起来却烦死人,不是没用就是太复杂,今天向大家推荐一个简单实用的控件,该控件在不断更新,而且有专门的网站对它进行维护,所以值得一看. 先说它 ...

  7. neural style论文解读

    相关的代码都在Github上,请参见我的Github,https://github.com/lijingpeng/deep-learning-notes 敬请多多关注哈~~~ 概述 在艺术领域,艺术家 ...

  8. Samba通过ad域进行认证并限制空间大小《转载》

    本文实现了samba服务被访问的时候通过windows域服务器进行用户名和密码验证;认证通过的用户可以自动分配500M的共享空间;在用户通过windows域登陆系统的时候可以自动把这块空间映射成一块硬 ...

  9. ORACLE SQL单行函数(一)【weber出品必属精品】

    1.SUBSTR:求父串中的子串 SUBSTR('HelloWorld',1,5) 1:代表子串的起始位置,如果为正,正数,如果为负,倒数 5:代表字串的终止位置,只能向右数,可以省略,如果省略就是数 ...

  10. 简单的批量读取外部insert文并插入DB

    package com.tongxiang.item.base.dao; import java.io.BufferedReader; import java.io.File; import java ...