#include "bits/stdc++.h" // Ignacy Boehlke using namespace std; // XIII LO Szczecin template<class A,class B>ostream&operator<<(ostream&os,pair<A,B>p){return os<<'{'<<p.first<<", "<<p.second<<'}';} template<class T>auto operator<<(ostream&os,T v)->decltype(v.end(),os){os<<'{';int i=0;for(auto e:v)os<<(", ")+2*!i++<<e;return os<<'}';} #ifdef DEBUG #define LOG(x...)cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...)<<'\n';}(x) #else #define LOG(...)(void)0 #endif #define ssize(x)((int)x.size()) #define FOR(a,b,c)for(int a=(b);a<=(c);a++) #define REP(a,b)FOR(a,0,(b)-1) #define ALL(x)(x).begin(), (x).end() #define fi first #define se second using ll=long long; constexpr int MAX = 130000; int main() { vector<int> pref(MAX); FOR(i, 1, MAX - 1) pref[i] = pref[i - 1] + __builtin_popcount(i); int n; cin >> n; vector<int> c; while (n != 0) { int l = 1, r = (c.empty() ? MAX - 1 : c.back() - 1); while (l != r) { int m = (l + r) / 2; if (pref[m] >= n) r = m; else l = m + 1; } c.push_back(l); n -= __builtin_popcount(l); } cout << ssize(c) << '\n'; for (int e : c) cout << e << ' '; cout << '\n'; }
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 | #include "bits/stdc++.h" // Ignacy Boehlke using namespace std; // XIII LO Szczecin template<class A,class B>ostream&operator<<(ostream&os,pair<A,B>p){return os<<'{'<<p.first<<", "<<p.second<<'}';} template<class T>auto operator<<(ostream&os,T v)->decltype(v.end(),os){os<<'{';int i=0;for(auto e:v)os<<(", ")+2*!i++<<e;return os<<'}';} #ifdef DEBUG #define LOG(x...)cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...)<<'\n';}(x) #else #define LOG(...)(void)0 #endif #define ssize(x)((int)x.size()) #define FOR(a,b,c)for(int a=(b);a<=(c);a++) #define REP(a,b)FOR(a,0,(b)-1) #define ALL(x)(x).begin(), (x).end() #define fi first #define se second using ll=long long; constexpr int MAX = 130000; int main() { vector<int> pref(MAX); FOR(i, 1, MAX - 1) pref[i] = pref[i - 1] + __builtin_popcount(i); int n; cin >> n; vector<int> c; while (n != 0) { int l = 1, r = (c.empty() ? MAX - 1 : c.back() - 1); while (l != r) { int m = (l + r) / 2; if (pref[m] >= n) r = m; else l = m + 1; } c.push_back(l); n -= __builtin_popcount(l); } cout << ssize(c) << '\n'; for (int e : c) cout << e << ' '; cout << '\n'; } |