Summation of Four Primes - PC110705
欢迎访问我的新博客:http://www.milkcu.com/blog/
原文地址:http://www.milkcu.com/blog/archives/uva10168.html
原创:Summation of Four Primes - PC110705
作者:MilkCu
题目描述
|
|||||
Waring's prime number conjecture states that every odd integer is either prime or the sum of three primes. Goldbach's conjecture is that every even integer is the sum of two primes. Both problems have been open for over 200 years.
In this problem you have a slightly less demanding task. Find a way to express a given integer as the sum of exactly four primes.
Input
Output
Sample Input
24 36 46
Sample Output
3 11 3 7 3 7 13 13 11 11 17 7
解题思路
代码实现
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int isPrime(int x) {int s = sqrt(x);for(int i = 2; i <= s; i++) {if(x % i == 0) {return 0;}}return 1;
}
void twopart(int x, int & a, int & b) {for(int i = 2; i <= x / 2; i++) {if(isPrime(i) && isPrime(x - i)) {a = i;b = x - i;return;}}return;
}
int main(void) {int n;while(cin >> n) {if(n <= 7) {cout << "Impossible." << endl;continue;}if(n % 2) {int a, b;twopart(n - 2 - 3, a, b);cout << "2 3 " << a << " " << b << endl;} else {int a, b;twopart(n - 2 - 2, a, b);cout << "2 2 " << a << " " << b << endl;}}return 0;
}
本文地址:http://blog.csdn.net/milkcu/article/details/23599369
Summation of Four Primes - PC110705相关推荐
- UVA10168 Summation of Four Primes【筛选法】
Euler proved in one of his classic theorems that prime numbers are infinite in number. But can every ...
- 题解:Summation of Four Primes(整数分解四个素数和)
每个大于4的整数可以以转换为两个素数和 Euler proved in one of his classic theorems that prime numbers are infinite in nu ...
- UVA - 10168 Summation of Four Primes(哥德巴赫猜想)
题目链接:点击查看 题目大意:给出一个n,若能将其分解成四个质数之和,请分解,否则输出Impossible. 题目分析:首先我们知道,最小的质数是2,四个2之和是8,所以当n小于8的时候肯定无解 其次 ...
- Competitive Programming 3题解
题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...
- π-Algorithmist分类题目(1)
原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(1) Sorting UVAL ...
- ICPC程序设计题解书籍系列之八:(美)斯基纳等:《挑战编程-程序设计竞赛训练手册》
S书<挑战编程--程序设计竞赛训练手册>题目一览 1 Getting Started UVA100 POJ1207 HDU1032 The 3n + 1 problem[水题] - 海岛B ...
- ICPC程序设计题解书籍系列之六:吴永辉:《算法设计编程实验》
第1章 Ad Hoc问题 POJ2661 HDU1141 ZOJ2545 UVA10916 Factstone Benchmark[Ad Hoc] UVA10037 Bridge[贪心] POJ257 ...
- (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO
下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...
- UVa Online Judge 工具網站
UVa Online Judge 工具網站 转自http://www.csie.ntnu.edu.tw/~u91029/uva.html Lucky貓的ACM園地,Lucky貓的 ACM 中譯題目 M ...
最新文章
- 从计算机视觉(slam)和摄影测量两个维度进行BA算法原理推导
- 备份oracle中的大表
- 戴维南定律和诺顿定律
- TextView显示不同颜色的文本,及文本变色可点击工具类
- CF464E The Classic Problem(主席树+哈希+最短路)
- java 注解 方法 参数_java在注解中绑定方法参数的解决方案
- javaweb中mysql数据库的回滚操作代码
- myeclipse 添加mysql数据库_myeclipse添加数据库
- 3.15 曝光:40 亿 AI 骚扰电话和 11 家合谋者
- [转载] python difference用法_set.difference() 的用法(python3)_python3 set集合,三元运算以及
- 0. Unix / Linux操作系统介绍
- NumberFormat的使用
- Cypress USB 芯片固件修改,改序列号(Serial Number)
- jde多目标_CVPR 2020 多目标跟踪算法JDE 训练
- html5 电子白板 直播,基于HTML5的电子白板的设计与实现
- 驾考通-小型汽车考试
- 主流实时流处理计算框架Flink初体验
- java数据类型面试题
- 【linux kernel】一文总结initramfs的使用
- password_hash/password_verify/(JAVA)