Codeforces Round #324 (Div. 2) D. Dima and Lisa (哥德巴赫猜想 + 暴力)

D. Dima and Lisa

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. 1 ≤ k ≤ 3
  2. 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.

Examples

input

27

output

35 11 11

Note

A prime is an integer strictly larger than one that is divisible only by one and by itself.

题意是将一个奇数n拆分成三个以下素数之和。

根据哥德巴赫猜想,任一大于7的奇数都可写成三个质数之和。这样我们随意找一个是奇数的素数a作为第一个素数,这样子n-a就是偶数了,根据原始的哥德巴赫猜想,任一大于2的偶数都可写成两个质数之和,我们就可以放心的去找剩下的两个素数。素数之间的距离最多只有几百,所以实际上是可以放心暴力的(然而我并不知道)。所以我套了米勒-罗宾算法来检测素数(就当做试模板了)。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
#define ll long long
const ll mod = 1e9 + 7;
const int maxn = 1e5 + 10;
ll mod_mul(ll a, ll b, ll n) {
    ll res = 0;
    while(b) {
        if(b&1)    res = (res + a) % n;
        a = (a + a) % n;
        b >>= 1;
    }
    return res;
}
ll mod_exp(ll a, ll b, ll n) {
    ll res = 1;
    while(b) {
        if(b&1)    res = mod_mul(res, a, n);
        a = mod_mul(a, a, n);
        b >>= 1;
    }
    return res;
}
bool miller_rabin(ll n) {
    if(n == 2 || n == 3 || n == 5 || n == 7 || n == 11)    return true;
    if(n == 1 || !(n%2) || !(n%3) || !(n%5) || !(n%7) || !(n%11))    return false;
    ll x, pre, u;
    int i, j, k = 0;
    u = n - 1;
    while(!(u&1)) {
        k++; u >>= 1;
    }
    srand((ll)time(0));
    for(i = 0; i < 20; ++i) {
        x = rand()%(n-2) + 2;
        if((x%n) == 0)    continue;

        x = mod_exp(x, u, n);
        pre = x;
        for(j = 0; j < k; ++j) {
            x = mod_mul(x, x, n);
            if(x == 1 && pre != 1 && pre != n-1)    return false;
            pre = x;
        }
        if(x != 1)    return false;
    }
    return true;
}
int main() {
    ll n;
    while(~scanf("%I64d", &n)) {
        ll a;
        if(n == 3 || n == 5) printf("1\n%I64d\n", n);
        else {
            if(n == 9) {printf("2\n2 7\n"); return 0;}
            if(n == 7) {printf("1\n7\n"); return 0;}
            a = n / 3;
            if(a % 2 == 0) a++;
            while(1) {
                a += 2;
                if(miller_rabin(a)) break;
            }
            puts("3");
            ll b, c;
            for(b = 3; ;b += 2) {
                c = n - b - a;
                //cout << b << " " << c << " " << a << endl;
                if(miller_rabin(b) && miller_rabin(c)) {
                    break;
                }
            }
            printf("%I64d %I64d %I64d\n", a, b, c);

        }
    }
}
时间: 2025-01-01 11:12:10

Codeforces Round #324 (Div. 2) D. Dima and Lisa (哥德巴赫猜想 + 暴力)的相关文章

Codeforces Round #324 (Div. 2) D - Dima and Lisa(哥德巴赫猜想)

1 #include<bits/stdc++.h> 2 using namespace std; 3 4 /** 5 据哥德巴赫猜想:任意一个偶数可以拆成两个质数 6 n-- 直到质数 t , n-t 是偶数 , 将n-t 拆分成两个质数 7 8 */ 9 10 bool check(int x) { 11 for (int i = 2; i * i <= x; i++) 12 if (x % i == 0) return false; 13 return true; 14 } 15 1

Codeforces Round #422 (Div. 2) A. I&#39;m bored with life 暴力

A. I'm bored with life Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the

Codeforces Round #324 (Div. 2)

今天写写cf上以前的水题,找找自信 A. Olesya and Rodion 此题要求一个能被t整除的n位数,直接t为开始,后面全部为0. 当然,需要排除位数为1但t=10的情况. #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int main() { int n,t,i; scanf("%d%d"

Codeforces Round #214 (Div. 2)---C. Dima and Salad

Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something. Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the

Codeforces Round #214 (Div. 2) C. Dima and Salad 背包

C. Dima and Salad Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something. Dima and Seryozha have n fruits in the fridge. Each fruit has t

Codeforces Round #324 (Div. 2) (快速判断素数模板)

蛋疼的比赛,当天忘了做了,做的模拟,太久没怎么做题了,然后C题这么简单的思路却一直卡到死,期间看了下D然后随便猜了下,暴力了下就过了. A.找一个能被t整除的n位数,那么除了<=10以外,其他都可以用长度为n的10或100,1000 ... 来往上加几个数而得到 #include <iostream> #include <stdio.h> #include <set> #include <algorithm> #include <string.h

Codeforces Round #324 (Div. 2)C. Marina and Vasya set

                                                      C. Marina and Vasya Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. Mor

Codeforces Round #324 (Div. 2) E

这题贪心,考虑先放第一个,然后从第一个数在p中的位置, 不断的往前走,和在他后面的那些数组进行交换,因为这样交换可以提高最大的效率,就是说你花费了1但是使得两个点都朝他的木匾节点减少了1 #include <iostream> #include <algorithm> #include <cstdio> #include <vector> #include <cmath> using namespace std; const int maxn=2

Codeforces Round #262 (Div. 2) E. Roland and Rose 暴力

E. Roland and Rose Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/460/E Description Roland loves growing flowers. He has recently grown a beautiful rose at point (0, 0) of the Cartesian coordinate system. The ro