#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pi pair<int,int> #define vi vector<int> #define vvi vector<vi> #define vll vector<ll> #define ST first #define ND second #define PB push_back void Solve() { int n; cin >> n; int k=0; int sum=0; vi Output(0); while(sum<n) { ++k; sum+=__builtin_popcount(k); } Output.PB(k); n-=__builtin_popcount(k); sum-=__builtin_popcount(k); --k; while(n>0) { if(sum-__builtin_popcount(k)>=n){ sum-=__builtin_popcount(k); --k; continue; }else{ Output.PB(k); sum-=__builtin_popcount(k); n-=__builtin_popcount(k); --k; } } cout << Output.size() << "\n"; for(int i=0; i<Output.size(); ++i) cout << Output[i] << ' '; cout << "\n"; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; //cin >> t; t=1; while(t--) { Solve(); } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pi pair<int,int> #define vi vector<int> #define vvi vector<vi> #define vll vector<ll> #define ST first #define ND second #define PB push_back void Solve() { int n; cin >> n; int k=0; int sum=0; vi Output(0); while(sum<n) { ++k; sum+=__builtin_popcount(k); } Output.PB(k); n-=__builtin_popcount(k); sum-=__builtin_popcount(k); --k; while(n>0) { if(sum-__builtin_popcount(k)>=n){ sum-=__builtin_popcount(k); --k; continue; }else{ Output.PB(k); sum-=__builtin_popcount(k); n-=__builtin_popcount(k); --k; } } cout << Output.size() << "\n"; for(int i=0; i<Output.size(); ++i) cout << Output[i] << ' '; cout << "\n"; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; //cin >> t; t=1; while(t--) { Solve(); } return 0; } |