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;
 }


}

2 comments:

  1. 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.

    ReplyDelete
  2. input: 10
    output: 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 .

    ReplyDelete

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.