当前位置:网站首页>2020.11.22 Exam Goldbach Conjecture Solution
2020.11.22 Exam Goldbach Conjecture Solution
2022-08-10 03:21:00 【bj_hacker】
题目
哥德巴赫猜想
【问题描述】
哥德巴赫猜想:任何大于 4 can be divided into the sum of two odd prime numbers.
比如:8=3+5.
20=3+17=7+13
42=5+37=11+31=13+29=19+23
你的任务是:验证小于 1000 000 The numbers satisfy Goldbach's conjecture.
【输入】
输入包含多组测试数据,One for each set of test data n(6<=n<1000 000).
读入以 0 结束.
【输出】
对于每组数据,输出形如 n=a+b,其中 a,b 是奇质数.若有多组满足条件的 a,b,输
出 b-a 最大的一组.若无解,输出“Goldbach’s conjecture is wrong.
思路
Ehrlich sieve method+Loop to determine another number
代码实现
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
int n;
bool as[maxn];
inline void init(){
as[1]=true;
for(int i=2;i<=1000000;i++){
if(as[i])continue;
for(int j=2*i;j<=1000000;j+=i)as[j]=true;
}
}
int main(){
init();
while(1){
scanf("%d",&n);
if(!n)break;
if(n%2==1){
printf("Goldbach’s conjecture is wrong\n");
continue;
}
printf("%d = ",n);
for(int i=3;i<=n;i++){
if(as[i])continue;
if(!as[n-i]){
printf("%d + %d\n",i,n-i);
break;
}
}
}
return 0;
}
边栏推荐
猜你喜欢
随机推荐
Data Governance (5): Metadata Management
中英文互译在线翻译-在线翻译软件
免费文档翻译软件电脑版软件
【论文粗读】(NeurIPS 2020) SwAV:对比聚类结果的无监督视觉特征学习
状态压缩小经验
Under pressure, there must be cowards
FusionConpute虚拟机的发放与管理
桌面云组件介绍与安装
Arcgis进阶篇(1)——安装Arcgis Enterprise,创建sde库
xss的DOMPurify过滤框架:一个循环问题以及两个循环问题
storage of data in memory
openpose脚部标注问题梳理
翻译软件免费版下载-免费版翻译软件下载
.Net面试经验总结
Fusion Compute网络虚拟化
Open3D 泊松盘网格采样
在蓝图中给组件动态加子Actor组件
【机器学习】随机森林、AdaBoost、GBDT、XGBoost从零开始理解
《GB39707-2020》PDF下载
The flask to add and delete