求助
  • 板块灌水区
  • 楼主lty2023
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/11/29 13:39
  • 上次更新2024/11/29 17:00:17
查看原帖
求助
1037200
lty2023楼主2024/11/29 13:39

完善程序: (哥德巴赫猜想)哥德巴赫猜想是指,任一大于 2 的偶数都可写成两个质数之和。 迄今为止,这仍然是一个著名的世界难题,被誉为数学王冠上的明珠。试编写程 序,验证任一大于 2 且不超过 n 的偶数都能写成两个质数之和。

#include<bits/stdc++.h>
using namespace std;
int main(){
	const int SIZE=1000;
	int n,r,p[SIZE],ans;
	bool tmp;
	cin>>n;
	r=1;
	p[1]=2;
	for(int i=3;i<=n;i++){
		①;
		for(int j=1;j<=r;j++){
			if(i%②==0){
				tmp=false;
				break;
			}
		}
		if(tmp){
			r++;
			③;
		}
	}
	ans=0;
	for(int i=2;i<=n/2;i++){
		tmp=false;
		for(int j=1;j<=r;j++){
			for(int k=j;k<=r;k++){
				if(i+i==④){
					tmp=true;
					break;
				}
			}
		}
	}
	if(tmp){
		ans++;
	}
	cout<<ans<<endl;
}

这程序是什么思路啊!

2024/11/29 13:39
加载中...