歌德巴赫猜想:
任何大于6的偶数均可以表示为两个奇素数的和.
#include "stdafx.h"
#include <iostream>
#include <math.h>
using namespace std;
bool Fun(int number)
{
double num = (double)number;
int i = 2;
bool f = 1;
while((i <= sqrt(num)) && f)
{
if(number % 2 == 0)
f = 0;
else
i++;
}
return f;
}
int _tmain(int argc, _TCHAR* argv[])
{
int sta = 8, add1, k = 0, add2, n;
cout << "Input a number(>8) : " << endl;
cin >> n;
while(sta < n)
{
add1 = 2;
add2 = sta - add1;
while(!Fun(add1) || !Fun(add2))
{
add1 = add1 + 1;
add2 = sta - add1;
}
int row = 5;
if (k > row)
{
cout << endl;
k = 0;
}
cout << sta << " = " << add1 << " + " << add2 << endl;
k++;
sta = sta + 2;
}
cout << "在你给定的范围内“歌德巴赫猜想”已被证明!" << endl;
return 0;
}
最近,越来越觉得自己的基础不行了,哎,得从基础打牢, 晚上回来还是动动手.