(数论)哥德巴赫猜想

  • 关于偶数的哥德巴赫猜想:任一大于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代码:

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值