Source Code
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define s second
#define f first
#define pb push_back
signed main()
{
    int cur=1;
    vector<int>ans;
    int curs=0;
    int x;
    cin>>x;
    while(curs<x)
    {
        if(curs+cur>x)
        {
            ans.back()+=x-curs;
            break;
        }
        curs+=cur;
        cur++;
        ans.pb(cur-1);
    }
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++)
        cout<<ans[i]<<" \n"[i+1==ans.size()];
    return 0;
}
Copy
Want More! ahmedfouadnew
GNU G++17
181 ms
22.4 MB
Accepted