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 ≤ 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.
Sample test(s)
input
27
output
3 5 11 11
Note
A prime is an integer strictly larger than one that is divisible only by one and by itself.
-------------------------------------------editorial-----------------------------------------------------------------------------
according to number theory , any odd no can be writen as a sum of 3 prime number
also any even no can be writen as a sum of 2 prime numbers
now for any give odd number we set first no as 3 , so now no become a even no (since odd no -3=even number ) , now we need to find 2 prime numbers which can give sum= that even number ,
we can do it very easily , there is another very big observation that any even no can be writen as a sum of 2 prime no , and one of the prime number must be <10004, soo we iterate for all prime number till 10004 , and find 3rd number , now check whether that 3rd no is prime no or not
since 3rd no can be large , so we cant use seiv , so we need to check in sqrt(no) complexity ...
there are some special cases , till 7
-----------------------------------------------------------code--------------------------------------------------------------
#include<iostream>
typedef long long int lli;
#include<bits/stdc++.h>
using namespace std;
int prime[1000000];
int main()
{
prime[1]=1;
prime[0]=1;
for(int i=2;i<=1000000;i++)
{
if(!prime[i])
for(int j=2;j*i<=1000000;j++)
{
prime[i*j]=1;
}
}
lli n;
cin>>n;
if(n==5)
{
cout<<"1"<<endl;
cout<<"5"<<endl;
return 0;
}
if(n==3)
{
cout<<"1"<<endl;
cout<<"3"<<endl;
return 0;
}
if(n==7)
{
cout<<"3"<<endl;
cout<<"2 2 3"<<endl;
return 0;
}
cout<<3<<endl;
cout<<3<<" ";
n-=3;
for(int i=2;i<=100004;i++)
{
if(!prime[i])
{
//cout<<" checking "<<i<<endl;
lli re=n-i;
//cout<<" re "<<re<<endl;
int loop=sqrt(re);
// cout<<" loop till "<<loop<<endl;
int f=0;
for(int j=2;j<=loop;j++)
{
if(re%j==0)
{
//cout<<" fali for "<<j<<endl;
f=1;
break;
}
}
if(f==0)
{
cout<<i<<" "<<re<<endl;
return 0;
}
}
}
}