Source Code
#include <bits/stdc++.h>
#define endl "\n"
#define debug(a) cout << #a << ": " << a << endl
#define debugLine() cout << "==============" << endl
#define tick() cout << "Tick" << endl
#define testCases() int t; cin >> t; while(t--)
#define all(a) a.begin(), a.end()
#define fillWith(a, b) memset(a, b, sizeof(a))
#define Mod 1000000007
#define goFast() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define files(x) freopen(x, "r", stdin)
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    goFast();
    ll N;
    cin >> N;
    vector<int> answer;
    while(N != 0)
    {
        if(N != 4 && N != 2 && N != 1)
        {
            if(N & 1)
            {
                answer.push_back(N / 2 + 1);
                N -= N / 2 + 1;
            }
            else
            {
                answer.push_back(N / 2);
                N -= N / 2;
            }
        }
        else if(N == 4)
        {
            answer.push_back(3);
            answer.push_back(1);
            break;
        }
        else if(N == 2)
        {
            answer.push_back(2);
            break;
        }
        else if(N == 1)
        {
            answer.push_back(1);
            break;
        }
    }
    cout << answer.size() << endl;
    for(auto it : answer)
        cout << it << " ";
    cout << endl;
}
Copy
Want More! AhmadShahal
GNU G++17
0 ms
524 KB
Wrong Answer