哥德巴赫猜想_哥德巴赫猜想是什么
哥德巴赫猜想由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“哥德巴赫猜想是什么”。
描述
Geeker对计算机和数学非常感兴趣,刚学完计概的他有一天突发奇想能不能编段小程序验证下哥德巴赫猜想了,即对于任意给定的偶数m(m>=6且不超出int范围),验证其能够表示成2个奇素数之和
关于输入
一个偶数m
关于输出
2个和是m的奇素数,它们之间用空格分隔。如果有多组满足,则每组之间需要换行(2个奇素数输出时候小的在前面,大的在后面)。每组之间没有重复,存在多个组满足的情况下按第一个奇数从小到大排列,见例子输出
例子输入
例子输出372923
#include
#include
#include
#include
using namespace std;
void sushu();
void suprint();
int N=0;// 读入的数值
string str=“1 2 3 5”;//全部素数写入到str
int allsushu[400]={1,2,3,5};//全部素数写入到数组中
int Count=4;//全部素数的个数
void main()
{
while(N==0)
{
cout
cin>>N;
cout
if(N%2!=0)
{
cout
N=0;
}
}
sushu();
if(N==2)
cout
else if(N==4)
cout
else
cout
suprint();
}
void sushu()//得到小于su的所有素数
{
if(N==2)
cout
else if(N==4)
cout
else
{
for(int cl=6;cl
{
int n=sqrt(cl);
for(int i=2;i
{
if(cl%i==0)
break;
}
if(i==n+1)
{
string stradd;
stringstream stream;
stream
stream>>stradd;//将stream中的值抽取到stradd中str=str+' '+stradd;
allsushu[Count]=cl;
Count++;
}
}
}
}
void suprint()//打印两素数的和是N的素数
{
cout
if(N==2)
cout
else if(N==4)
cout
else
{
for(int i=0;i
for(int j=i+1;j
if(allsushu[i]+allsushu[j]==N)
cout
}
PS题目要求m要