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

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

 

 
提交地址POJ2262
 

 
题解 :
怎么又是水题...
先筛法出素数;
然后暴力判断;
 

 
Code
 #include <iostream>
#include <cstdio>
using namespace std; bool isprime[]; //1 -> 合数, 0 -> 质数 int main()
{
isprime[] = isprime[] = ;
for (register int i = ; i <= ; i ++)
{
if (isprime[i]) continue;
for (register int j = i ; j <= /i ; j ++)
isprime[i*j] = ;
} int n;
while (scanf("%d", &n) != EOF)
{
if (n == ) return ;
for (register int i = ; i <= n ; i ++)
{
if (!isprime[i] and !isprime[n-i])
{
printf("%d = %d + %d\n", n, i, n-i);
break;
}
}
} }

最新文章

  1. java集合类深入分析之Queue篇
  2. [android]判断位置服务是否打开
  3. Github windows客户端简单使用教程
  4. 优化数据库的方法及SQL语句优化的原则
  5. Qt回忆录之配置开发环境
  6. qmf
  7. 【温故知新】c#异步编程模型(APM)--使用委托进行异步编程
  8. java5 新特性
  9. getimagesize函数介绍
  10. pip install robotframework-sshlibrary提示: Microsoft Visual C++ 9.0 is required
  11. iOS 网络与多线程--2.同步Get方式的网络请求(阻塞)
  12. nginx+uwsgi+flask搭建python-web应用程序
  13. URAL 1297 最长回文子串(后缀数组)
  14. 【构造】UVa 11387 The 3-Regular Graph
  15. vue 中 vue-router、transition、keep-alive 怎么结合使用?
  16. tqdm介绍及常用方法
  17. Numeric Type Attributes
  18. 如何得知当前机器上安装的PowerShell是什么版本的?
  19. Socket缓冲区
  20. 【LOJ 2542】【PKUWC2018】 随机游走(最值反演 + 树上期望dp)

热门文章

  1. springboot logback日志的使用
  2. Elasticsearch(9) --- 聚合查询(Bucket聚合)
  3. C++虚函数表和对象存储
  4. 阿里巴巴 Sentinel + InfluxDB + Chronograf 实现监控大屏
  5. python unittest+parameterized,单元测试框架+参数化
  6. 数据结构之二叉树篇卷三 -- 二叉树非递归遍历(With Java)
  7. 浅谈Spring的事务隔离级别与传播性
  8. Ubuntu 查看操作系统的位数
  9. mybatis collection和association使用区别
  10. git基本命令整合