F - Dima and Lisa

Problem description

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.

解题思路:将一个奇数拆分成1~3个素数,暴力即过!

哥德巴赫猜想:随便取某一个奇数,比如77,可以把它写成三个素数之和,即77=53+17+7;再任取一个奇数,比如461,可以表示成461=449+7+5,也是三个素数之和,461还可以写成257+199+5,仍然是三个素数之和。例子多了,即发现“任何大于5的奇数都是三个素数之和。”

AC代码(31ms):

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 bool isprime(int x){
 4     if(x<=1)return false;
 5     for(int i=2;i*i<=x;++i)
 6         if(x%i==0)return false;
 7     return true;
 8 }
 9 int main(){
10     int n;cin>>n;bool flag=false;
11     if(isprime(n))cout<<"1\n"<<n<<endl;//如果本身是素数,直接输出即可
12     else{
13         for(int i=3;i<=n;i+=2){//从3开始按奇数来枚举
14             if(isprime(i)){
15                 int tmp=n-i;
16                 if(isprime(tmp)){cout<<"2\n"<<i<<‘ ‘<<tmp<<endl;break;}
17                 for(int j=3;j<=n;j+=2)//从3开始按奇数来枚举
18                     if(isprime(j) && isprime(tmp-j)){cout<<"3\n"<<i<<‘ ‘<<j<<‘ ‘<<(tmp-j)<<endl;flag=true;break;}
19                 if(flag)break;
20             }
21         }
22     }
23     return 0;
24 }

原文地址:https://www.cnblogs.com/acgoto/p/9157876.html

时间: 2024-08-04 10:05:48

F - Dima and Lisa的相关文章

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

CodeForces 584D Dima and Lisa

1e9 以内的判断一个数是否是素数,可以直接朴素的暴力. 这倒题除了考虑1e9以内的素数的判断,还有一个歌德巴赫猜想:任意一个奇数都可一分解为三个素数的和. 第三个结论:素数是密集的,1e9以内,相邻的素数之间的间隔不会大于300,所以直接枚举也不会浪费掉太多的时间. 这里还有一点需要注意的是:朴素的判断是否是素数,i<=saqrt(n).今天的天梯赛由于记错了这个条件,导致没有求出素数,一道二十分的题没有做,好伤心. Dima and Lisa Time Limit:1000MS     Me

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

Gym 240668 - A/B/C/D/E - (Done)

链接:https://codeforces.com/gym/240668 A - Olesya and Rodion - [水] 题解:注意到 $t$ 的范围是 $[2,10]$,对于位数小于 $2 \times 3 \times \cdots \times 10 = 3628800$ 的数,暴力枚举去找:否则就直接在 $3628800$ 后面补零即可. AC代码: #include<bits/stdc++.h> using namespace std; int n,t; int p10[8]

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"

过分过分进货价获国家

http://f.dangdang.com/group/24554/3491082/http://f.dangdang.com/group/24554/3491087/http://f.dangdang.com/group/24554/3491094/http://f.dangdang.com/group/24554/3491099/http://f.dangdang.com/group/24554/3491105/http://f.dangdang.com/group/24554/349111

我们找个地方看好戏

http://v.qq.com/page/f/y/4/m041433ssun.html http://v.qq.com/page/f/y/4/m041433ssun.html http://v.qq.com/page/f/y/4/m04143o3lhg.html http://v.qq.com/page/f/y/4/m04144675h3.html http://v.qq.com/page/f/y/4/m04144k1k1j.html http://v.qq.com/page/f/y/4/m04

Codeforces Round #262 (Div. 2) 460B. Little Dima and Equation(枚举)

题目链接:http://codeforces.com/problemset/problem/460/B B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Dima misbehaved during a math lesson a lot and the nas

cf584DDima 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 nume