5.3哥德巴赫猜想的近似证明

#include  <iostream>
#include <cmath>
using namespace std;

int isPrime(int i) {//判断素数
	int n,flag=1;
	if(i==1) flag=0;
	for(n=2;n<i;n++)
		if(i%n==0) {
			flag=0;
			break;
		}
	if(flag==1)	return 1;
	else	return 0;	
}

int isGoldbach(int a) {//判断该偶数是否符合哥德巴赫猜想
	int i,flag=0;
	for(i=1;i<=a/2;i++) {
		if(isPrime(i) && isPrime(a-i)) {
			flag=1;
			cout<<a<<"="<<i<<"+"<<a-i<<" ";
			break;
		}
	}
	if(flag==1)	return 1;
	else 	return 0;
}

int TestifyGB_Guess(int low,int high) {  //在某个范围内验证哥德巴赫猜想
	int i,j=0;
	int flag=0;
	for(i=low;i<=high;i++)
		if(i%2==0 &&i>2)
			if(isGoldbach(i)) {
				j++;
				if(j==5) {
					cout<<endl;
					j=0;
				}
			}else {
				flag=1;
				break;
			}
	if(flag==0)
		return 1;
	else
		return 0;
} 



int main() {
	if(TestifyGB_Guess(1,100))
		cout<<"Goldbach is right."<<endl;
	else
		cout<<"wrong!"<<endl;
	return 0;
}

  

拥抱明天! 不给自己做枷锁去限制自己。 别让时代的悲哀,成为你人生的悲哀。
原文地址:https://www.cnblogs.com/dd2hm/p/6780245.html