(数论)哥德巴赫猜想
2017-08-20 15:53
381 查看
关于偶数的哥德巴赫猜想:任一大于2的偶数都可写成两个素数之和。
关于奇数的哥德巴赫猜想:任一大于7的奇数都可写成三个质数之和的猜想。
【例题1 Dima and Lisa CodeForces - 584D 】
Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes.
More formally, you are given an odd numer n. Find a set of numbers pi (1 ≤ i ≤ k), such that
1 ≤ k ≤ 3
pi is a prime
The numbers pi do not necessarily have to be distinct. It is guaranteed that at least one possible solution exists.
Input
The single line contains an odd number n (3 ≤ n < 109).
Output
In the first line print k (1 ≤ k ≤ 3), showing how many numbers are in the representation you found.
In the second line print numbers pi in any order. If there are multiple possible solutions, you can print any of them.
Example
Input
27
Output
3
5 11 11
AC代码:
关于奇数的哥德巴赫猜想:任一大于7的奇数都可写成三个质数之和的猜想。
【例题1 Dima and Lisa CodeForces - 584D 】
Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes.
More formally, you are given an odd numer n. Find a set of numbers pi (1 ≤ i ≤ k), such that
1 ≤ k ≤ 3
pi is a prime
The numbers pi do not necessarily have to be distinct. It is guaranteed that at least one possible solution exists.
Input
The single line contains an odd number n (3 ≤ n < 109).
Output
In the first line print k (1 ≤ k ≤ 3), showing how many numbers are in the representation you found.
In the second line print numbers pi in any order. If there are multiple possible solutions, you can print any of them.
Example
Input
27
Output
3
5 11 11
AC代码:
#include<cstdio> #include<cstring> #include<cmath> #define ll long long using namespace std; bool isprime(ll n) { for(ll i=2;i<=sqrt(n);i++) if(n%i==0) return false; return true; } int main() { ll n; scanf("%lld",&n); if(isprime(n)) { printf("1\n"); printf("%lld\n",n); } else if(n%2==0) { for(ll i=n-1;i>=2;i-=2) { if(isprime(n-i) && isprime(i)) { printf("2\n"); printf("%lld %lld\n",i,n-i); break; } } } else { bool flag=0; for(ll i=n;i>=2;i-=2) { if(!isprime(i))continue; ll p=n-i; for(ll j=2;j<p;j++) { if(isprime(j) && isprime(p-j)) { printf("3\n"); printf("%lld %lld %lld\n",i,j,n-i-j); flag=1; break; } } if(flag)break; } } return 0; }
相关文章推荐
- (数论及应用2.3)nefu 2 猜想(哥德巴赫猜想:求一个合数可以使用几个素数对来表示)
- UVa 10168 Summation of Four Primes(数论-哥德巴赫猜想)
- CodeForces - 735D Taxes 数论 哥德巴赫猜想和弱哥德巴赫猜想
- Codeforces Round #382 (Div. 2) D. Taxes 数论、哥德巴赫猜想
- code forces 382 D Taxes(数论--哥德巴赫猜想)
- ural 1356. Something Easier(数论,哥德巴赫猜想)
- uva 10168 Summation of Four Primes(数论-哥德巴赫猜想)
- uva 10168 Summation of Four Primes(数论-哥德巴赫猜想)
- BZOJ3643 Phi的反函数(数论+搜索)
- 【正睿多校联盟Day4 T4 简单的数论题】
- 第三章第41题 哥德巴赫猜想
- HDU-1215 七夕节 数论 唯一分解定理 求约数之和
- LightOJ -kuangbin 数论
- UVA10140 Prime Distance【素数/数论】By cellur925
- TopCoder SRM 660 Div2 Problem 1000 - Powerit (数论)
- lightOJ 1278 Sum of Consecutive Integers(数论,数学推导)
- UVA 11426 - GCD - Extreme (II) (数论)
- 数论之欧几里德算法(三)
- 数论知识总结
- BZOJ 3122 SDOI2013 随机数发生器 数论 EXBSGS