循环-04. 验证“哥德巴赫猜想”(20)
来源:互联网 发布:数据分析主要做什么 编辑:程序博客网 时间:2024/05/24 00:22
循环-04. 验证“哥德巴赫猜想”(20)
数学领域著名的“哥德巴赫猜想”的大致意思是:任何一个大于2的偶数总能表示为两个素数之和。比如:24=5+19,其中5和19都是素数。本实验的任务是设计一个程序,验证20亿以内的偶数都可以分解成两个素数之和。
输入格式:
输入在一行中给出一个(2, 2 000 000 000]范围内的偶数N。
输出格式:
在一行中按照格式“N = p + q”输出N的素数分解,其中p <= q均为素数。又因为这样的分解不唯一(例如24还可以分解为7+17),要求必须输出所有解中p最小的解。
输入样例:24输出样例:
24 = 5 + 19
#include <iostream>#include <math.h>using namespace std;int integer(int x);int main(){int odd;cin>>odd;for(int i=2;i<odd;i++){if(integer(i)&&integer(odd-i)){printf("%d = %d + %d",odd,i,(odd-i));break;}}}int integer(int x){int option=1;if(x==1||x%2==0&&x!=2){option = 0;}for(int i=3;i<=sqrt(x);i++){if(x%i==0){option = 0;break;}}return option;}
0 0
- 循环-04. 验证“哥德巴赫猜想”(20)
- 循环-04. 验证“哥德巴赫猜想”(20)
- 循环-04. 验证“哥德巴赫猜想”(20)
- 循环-04. 验证“哥德巴赫猜想”(20)
- 循环-04. 验证“哥德巴赫猜想”(20)
- 循环-04. 验证“哥德巴赫猜想”(20)
- 循环-04. 验证“哥德巴赫猜想”(20)
- 循环-04. 验证“哥德巴赫猜想”(20)
- 循环-04. 验证“哥德巴赫猜想”(20)
- 循环-04. 验证“哥德巴赫猜想”(20)
- 循环-04. 验证“哥德巴赫猜想”(20)
- 循环-04. 验证“哥德巴赫猜想”
- VC++验证哥德巴赫猜想
- 验证哥德巴赫猜想
- 哥德巴赫猜想初步验证、、、、
- 验证“哥德巴赫猜想”
- 验证 哥德巴赫猜想
- 验证哥德巴赫猜想
- 工厂方法模式
- IOS开发网络篇之──ASIHTTPRequest详解
- Re-using Layouts with include
- 插入u盘导致系统重启电脑死机怎么办彻底解决方法
- mybatis简单应用(基于配置文件)
- 循环-04. 验证“哥德巴赫猜想”(20)
- OpenCV基础02(GUI+图像处理)
- 二分的相关技巧
- 设置JavaFX-CSS改变TreeView节点图标
- 异常——(4)Cannot change version of project facet Dynamic Web Module to 3.0
- 禁用 baloo_file_extractor 加速 ubuntu 14.04 (KDE)
- Android的系统架构
- 彼得原理(你一定会想看的)
- SQL 排序后取表中间的几行数据