/*
* [题意]
* 将一个数拆成四个素数的和,若不可能,则输出"Impossible."
*
* [解题方法]
* 根据哥德巴赫猜想,大于2的偶数能够分成两个素数的和
* (还没完全得到证明,但在题目所给范围内必然成立)
* 利用这个猜想,只要根据输入的奇偶性,定死前两个素数
* 若输入是奇数,则定为2 3 ? ?
* 若是偶数,则定为2 2 ? ?
* 剩余一个偶数再分成两个素数,问题迎刃而解
* PS:显然n<8无解
*/
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
#define M 10000000
int p[665000], vis[M];
int main()
{
int n, i, j, m, k = 0;
for (i = 2; i < M; i++)
{
if (!vis[i])
{
p[k++] = i;
for (j = i+i; j < M; j+=i) vis[j] = 1;
}
}
while (cin >> n)
{
if (n < 8) {
puts("Impossible.");
continue;
}
if (n & 1) cout << 2 << ' ' << 3, n -= 5;
else cout << 2 << ' ' << 2, n -= 4;
for (i = 0; i < k; i++)
if (!vis[n-p[i]])
break;
cout << ' ' << p[i] << ' ' << n-p[i] << endl;
}
return 0;
}
分享到:
相关推荐
V.M. Zolotarev的Modern theory of Summation of Random Variables,找了好久没有电子版,这个版本内部也有Hidden Page, 有需要的凑合着用吧!
Produce a table of the values of the series f(x)=sum(k from 1 to oo)1/(k*(k+x) for the 3001 values of x, x = 0.0, 0.1, 0.2, …, 300.00. All entries of the table must have an absolute error less than ...
Arranged by category, these series include arithmetical and geometrical progressions, powers and products of natural numbers, figurate and polygonal numbers, inverse natural numbers, exponential and ...
傅里叶-拉普拉斯级数Casaro均值的强求和,张微,张希荣,通过连续模界定的$L^{2}(sum_{d})$对数子空间中的傅里叶-拉普拉斯级数的强求和是一个很值得研究的内容。这篇文章经过推导证明得到了凸�
Effect of Different Variables on Overall Vertical Jump Height
1007 Numerical Summation of a Series 简单题,还是蛮有意思的 1045 HangOver 简单题 1049 I Think I Need a Houseboat 简单题 1028 Flip and Shift 简单题,可以DP/BFS/……,但是实际上有数学方法可直接判断...
This is the summation of MIT wireless conference
A novel summation inequality for stability analysis of discrete-time neural networks
You'll find a summation of all the skills learned in these chapters in a section called ‘Bringing it all Together’, followed by ‘The Gallery’, a selection of work from fantasy game artists from...
You'll find a summation of all the skills learned in these chapters in a section called ‘Bringing it all Together’, followed by ‘The Gallery’, a selection of work from fantasy game artists from...
% ------ Vertical step ------ for j = 1:N % Find non-zero in the... for k = 1:length(r1) % Update L(qij) by summation of L(rij)\r1(k) Lqij(r1(k) j) = Lci(j) + sum(Lrji(r1 j)) - Lrji(r1(k) j); end % for k
作者: Omar Alonso at the University of Chile, Chile. Introduction Structure of the chapters Naming of variables Probabilities Asymptotic notation About the programming languages On the code ...
非常详尽的数据结构中描述的算法 ...Summation formulas References Textbooks Papers Algorithms coded in Pascal and C Searching algorithms Sorting algorithms Selection algorithms Text algorithms
1003 Numerical Summation of a Series 求最大公因子 math 1004 Anagrams by Stack 给出输入序列和若干输出序列,求栈的处理过程 stack 1005 JUGS 给两杯子,倒出n升水的最少步骤 搜索 1006 Do the Untwist 字符...
Chapter 6 Summation formulas of Poisson and of Plana 6.1 The Poisson summation formula 6.2 Theta transformation formula and functional equation 6.3 The Hurwitz-Lerch zeta-function 6.4 Proof of results...
介绍求和符号的用法。
Fulgide, a kind of thermally irreversible photochromic compound, can be ... which can implement the readout of two individual orthogonal polarized images separately and the subtraction or summation of th
1.5.3 Superscripts/Subscripts and Summation Notation 9 1.5.4 Norm/Length of a Vector 11 1.5.5 Functions 11 1.5.6 U.S.-British versus SI Units 12 Chapter 2 Optimum Design Problem Formulation 15 2.1 The...
finding them, the W –Z method of summation, and estimates of algorithms and of certain combinatorial problems. Many challenging exercises accompany the text. Most of them have been the subjects of ...
how to implement some of the power and resource management principles that have been discussed in the document S60 Platform: Effective Power and Resource Management (available at ...