哥德巴赫猜想
Time Limit:3000MS Memory Limit:655366K
Total Submit:115 Accepted:55
Description
著名的哥德巴赫猜想可以陈述为:任何一个不小于6的偶数一定可以拆成两个质数的和。如6=3+3,8=5+3等,你的任务是将一个大于6的偶数n拆成两个最接近的质数p,q,满足p+q=n.
Input
输入包含多组测试数据。每组数据包含1个偶数n(n在6到1000000之间包含边界)。
Output
对于每组测试数据,输出两个质数p,q(p<=q)满足p+q=n。
Sample Input
6 8 10 200000
Sample Output
3 3 3 5 5 5 99871 100129
Source
ahstu@ICPC03
#include<iostream> using namespace std; int P[1000000]={0}; void Prime_list() { P[0]=P[1]=1; for(int i=2;i<1000000;i++) { for(int j=i*2;j<1000000;j+=i) P[j]=1; } } main() { int n; int i,cache; Prime_list(); while(cin>>n) { for(i=2;i<=n/2;i++) { if(P[i]==0&&P[n-i]==0) {cache=i;} } cout<<cache<<" "<<n-cache<<endl; } }
转载请注明出处,谢谢.Q_Q

浙公网安备 33010602011771号