SDUT 2809 Goldbach
来源:互联网 发布:mac 百度云下载太慢 编辑:程序博客网 时间:2024/04/30 11:39
Goldbach
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
The Goldbach’s Conjecture is stated like the following:
Every even number greater than 4 can be written as the sum of two odd prime numbers.
Your task is now to verify Goldbach\'s Conjecture for all even numbers less than a million.
输入
The input contains multiple test cases. Each test case consisted of an even integer n with 6 < n < 1000000. Input will be terminated by 0.
输出
For every test case, print one line of the form “n = a + b”, a < b, without quotes. Where a and b are odd prime numbers. If there is more than one pair of odd primes, you are to print the pair a, b with the maximized difference b - a. If there are no such pair, print a line saying “Goldbach\'s conjecture is wrong.”.
示例输入
8200
示例输出
8 = 3 + 520 = 3 + 17
#include <bits/stdc++.h>using namespace std;bool prim(int n){ for(int i=2;i*i<=n;i++) { if(n%i == 0) return false; } return true;}int main(){ int n; while(cin>>n && n) { for(int i=2;i<=n/2;i++) { if(prim(i)) { int t = n - i; if(prim(t)) { cout<<n<<" = "<<i<<" + "<<t<<endl; break; } } } } return 0;
}
0 0
- SDUT 2809 Goldbach
- Goldbach
- 长沙 Goldbach
- ZOJ3856 Goldbach
- Goldbach's Conjecture
- poj2262 Goldbach's Conjecture
- Goldbach's Conjecture
- Goldbach's Conjecture
- HOJ1459 Goldbach's Conjecture
- POJ2262 Goldbach's Conjecture
- 2262 Goldbach's Conjecture
- Goldbach's Conjecture
- POJ2262:Goldbach's Conjecture
- HDU1397:Goldbach's Conjecture
- Goldbach's Conjecture
- Goldbach's ConjectureCrawling
- Goldbach's Conjecture
- poj2262 Goldbach's Conjecture
- 七律 读百色画作有感
- js-defer
- Zigbee无线网络在线心电监测系统
- zend framework2-控制器插件创建公用对象函数,可在控制器直接调用
- Skiing
- SDUT 2809 Goldbach
- js-变量
- javascript 匿名函数
- js刷新页面方法大全
- Eclipse内Maven项目POM报错:com.thoughtworks.xstream.io.HierarchicalStreamDriver
- 2015年百度之星资格赛 A dp
- linux 线程编程:线程终止
- Java反射 具体需求实现案例三
- SDUT 2859 小明的骰子