作了一个歌德巴赫猜想的程序分享下
来源:互联网 发布:域名怎样备案 编辑:程序博客网 时间:2024/05/21 15:44
#include"stdafx.h"
#include"iostream"
using namespace std;
int IsJishu(int x){
if (x % 2 == 0)return 0;
return 1;
}
int IsSushu(int n){
for (int i = 2; i <= (int)sqrt(n); i++)
if (n%i == 0) return 0;
return 1;
}
int main(){
int x, i, j, k;
int a[1000] = { 0 };//1—x的存储所有素数
int m = 0;
int r = 0;
while (true)
{
while (true)
{
cout<<" 请输入要验证的数(歌德巴赫猜想)"<<endl;
cin >> x;
if (x < 5)
cout << "输入的数必须大于5,请重新输入" << endl;
else if (0 == IsJishu(x))
{
cout << "输入的数必须是奇数,请重新输入" << endl;
}
else
{
break;
}
}
for (i = 1; i < x; i++)
{
if (IsSushu(i)){ a[r++] = i; m++; }
}
for (i = 0; i <= m; i++)
for (j = 0; j <= m; j++)
for (k = 0; k <= m; k++)
if (x == a[i] + a[j] + a[k])cout << x << "=" << a[i] << "+" << a[j] << "+" << a[k] << endl;
}
return 0;
}
#include"iostream"
using namespace std;
int IsJishu(int x){
if (x % 2 == 0)return 0;
return 1;
}
int IsSushu(int n){
for (int i = 2; i <= (int)sqrt(n); i++)
if (n%i == 0) return 0;
return 1;
}
int main(){
int x, i, j, k;
int a[1000] = { 0 };//1—x的存储所有素数
int m = 0;
int r = 0;
while (true)
{
while (true)
{
cout<<" 请输入要验证的数(歌德巴赫猜想)"<<endl;
cin >> x;
if (x < 5)
cout << "输入的数必须大于5,请重新输入" << endl;
else if (0 == IsJishu(x))
{
cout << "输入的数必须是奇数,请重新输入" << endl;
}
else
{
break;
}
}
for (i = 1; i < x; i++)
{
if (IsSushu(i)){ a[r++] = i; m++; }
}
for (i = 0; i <= m; i++)
for (j = 0; j <= m; j++)
for (k = 0; k <= m; k++)
if (x == a[i] + a[j] + a[k])cout << x << "=" << a[i] << "+" << a[j] << "+" << a[k] << endl;
}
return 0;
}
1 0
- 作了一个歌德巴赫猜想的程序分享下
- 一个验证歌德巴赫猜想的小程序
- 一个验证歌德巴赫猜想的小程序
- 歌德巴赫猜想程序验证
- 歌德巴赫猜想的算法
- 歌德巴赫猜想的证明
- 歌德巴赫猜想的证明
- 验证歌德巴赫的猜想
- C++经典程序---歌德巴赫猜想的证明
- C/C++程序训练6---歌德巴赫猜想的证明
- C/C++程序训练6---歌德巴赫猜想的证明
- C/C++程序训练6---歌德巴赫猜想的证明
- C/C++程序训练6---歌德巴赫猜想的证明
- C/C++程序训练6---歌德巴赫猜想的证明
- C/C++程序训练6---歌德巴赫猜想的证明
- C/C++程序训练6---歌德巴赫猜想的证明
- C/C++程序训练6---歌德巴赫猜想的证明
- 歌德巴赫猜想的近似证明
- 聊一聊番外篇:屏幕,交互,ui
- 调用系统电话/短信/浏览器
- linux下vsftpd服务器的搭建
- php生成mysql数据字典
- spark配置环境的一些重要概念
- 作了一个歌德巴赫猜想的程序分享下
- spark入门介绍(菜鸟必看)
- 快速排序(二维数组)
- lightoj 1198Karate Competition
- VS2010中MFC利用TeeChart控件实现画图
- POJ2063
- java面向对象基础知识(三)
- 面试积累
- 黑马程序员--字符串