#include <bits/stdc++.h> #define f first #define s second #define vec vector #define pb push_back #define sz(x) (int)(x).size() #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() template<class T> bool umin(T &a ,const T &b){return (a>b?a=b,1:0);} template<class T> bool umax(T &a ,const T &b){return (a<b?a=b,1:0);} using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef long double ld; auto rng=bind(uniform_int_distribution<ll>(1,(ll)1e18),mt19937(time(0))); const int inf = (int)1e9 + 1; signed main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n; cin >> n; int x = 2 * n + 3; int sm = 0; for (int i = 1; i <= x; ++i) sm += __builtin_popcount(i); vec <int> ans; while (n != 0) { int f = __builtin_popcount(x); if ((sm - f) < n) { ans.pb(x); n -= f; } sm -= f; --x; } cout << ans.size() << '\n'; for (auto &z : ans) cout << z << ' '; return 0; } /* 1 2 1 7 2 18 7 9 3 18 5 17 3 8 14 18 4 7 7 17 3 20 1 18 4 11 10 11 */
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> #define f first #define s second #define vec vector #define pb push_back #define sz(x) (int)(x).size() #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() template<class T> bool umin(T &a ,const T &b){return (a>b?a=b,1:0);} template<class T> bool umax(T &a ,const T &b){return (a<b?a=b,1:0);} using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef long double ld; auto rng=bind(uniform_int_distribution<ll>(1,(ll)1e18),mt19937(time(0))); const int inf = (int)1e9 + 1; signed main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n; cin >> n; int x = 2 * n + 3; int sm = 0; for (int i = 1; i <= x; ++i) sm += __builtin_popcount(i); vec <int> ans; while (n != 0) { int f = __builtin_popcount(x); if ((sm - f) < n) { ans.pb(x); n -= f; } sm -= f; --x; } cout << ans.size() << '\n'; for (auto &z : ans) cout << z << ' '; return 0; } /* 1 2 1 7 2 18 7 9 3 18 5 17 3 8 14 18 4 7 7 17 3 20 1 18 4 11 10 11 */ |