1356. Something Easier
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
“How do physicists define prime numbers? Very easily: prime numbers are the number 2 and all the odd numbers greater than 2. They may show that this definition corresponds to the mathematical one: 3 is prime, 5 is prime, 7 is prime… 9? 9 is certainly not prime. Then: 11 is prime, 13 is prime. So 9 is the experiment mistake.”
From mathematical analysis course
Once physicist and mathematician argued how many prime numbers one needed for the purpose that their sum was equal to
N. One said that it wasn’t known and the other that 3 was always enough. The question is how many.
Input
The first line contains
T, an amount of tests. Then
T lines with integer
N follow (0 ≤
T ≤ 20; 2 ≤
N ≤ 10
9).
Output
For each test in a separate line you should output prime numbers so that their sum equals to
N. An amount of such prime numbers is to be minimal possible.
Sample
input | output |
---|---|
7 2 27 85 192 14983 3 7 | 2 23 2 2 2 83 11 181 14983 3 7 |
Problem Author: Aleksandr Bikbaev
Problem Source: USU Junior Championship March'2005
Problem Source: USU Junior Championship March'2005
根据哥德巴赫猜想,
任一大于2的偶数都可写成两个质数之和。
任一大于7的奇数都可写成三个素数之和。
#include <iostream>
using namespace std;
bool nprime(int k)
{
for(int i=2; i*i<=k; ++i)
{
if(k%i==0) return 1;
}
return 0;
}
int main()
{
int t,a;
cin>>t;
while(t--)
{
cin>>a;
if(!nprime(a)) cout<<a<<endl;
else if(a%2==0)
{
int k=a-3;
while(nprime(k) || nprime(a-k)) k-=2;
cout<<k<<" "<<a-k<<endl;
}
else
{
int k=a-2;
if(!nprime(k))
{
cout<<k<<' '<<2<<endl;
continue;
}
k-=2;
while(nprime(k)) k-=2;
cout<<k<<" ";
a=a-k;
if(a==4)
{
cout<<2<<' '<<2<<endl;
continue;
}
k=a-3;
while(nprime(k) || nprime(a-k)) k-=2;
cout<<k<<" "<<a-k<<endl;
}
}
}