Codeforces 749A. Bachgold Problem Solution
Solve in C++:
//AH Tonmoy
//Department of CSE ,Islamic University
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,r,re,i;
while(cin>>n)
{
if(n%2==0)
{
re=n/2;
printf("%d\n",re);
for(i=1;i<=re;i++)
{
printf("2 ");
}
}
else
{
r=(n-3);
re=(r/2);
printf("%d\n",re+1);
for(i=1;i<=re;i++)
{
printf("2 ");
}
cout<<"3";
}
cout<<endl;
}
}
//AH Tonmoy
//Department of CSE ,Islamic University
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,r,re,i;
while(cin>>n)
{
if(n%2==0)
{
re=n/2;
printf("%d\n",re);
for(i=1;i<=re;i++)
{
printf("2 ");
}
}
else
{
r=(n-3);
re=(r/2);
printf("%d\n",re+1);
for(i=1;i<=re;i++)
{
printf("2 ");
}
cout<<"3";
}
cout<<endl;
}
}
Sorry brother,your code is wrong.How could shows prime numbers between 1 to 10 equals to 5.Where actually its 4{2,3,5,7}.Hope you solve it.
ReplyDeleteinput: 10
ReplyDeleteoutput: 5
2 2 2 2 2
here 2 is prime number ,also we say sum of 5 number of '2' is 10 (2+2+2+2+2=10).I think you understand .