#include <bits/stdc++.h> typedef long long ll; using namespace std; const ll inf = 1e18 + 7; const ll mod = 1e9 + 7; ll n , m , k , ans = 0 , q; // ifstream in , out; int main() { ios_base::sync_with_stdio(0); cin.tie(0); /* for (int t = 5; t < 1000; t++) { string sin = "orn" , sout = "orn" , st = ""; ll kop = t; while (kop > 0) { st += char(kop % 10 + 48); kop /= 10; } if (st.size() == 0)st = "0"; reverse(st.begin() , st.end()); sin += st; sout += st; sin += ".in"; sout += ".out"; cout << sin << endl; in.open(sin); out.open(sout); */ cin >> n; ll s = 0 , last; for (int ch = 1; ch <= 1000000; ch++) { ll cur = __builtin_popcount(ch); if (s < n) { s += cur; last = ch; } else { break; } } ll need = s - n; vector<bool>have(last + 5 , 1); for (int i = last - 1; i; i--) { ll cur = __builtin_popcount(i); if (cur <= need) { need -= cur; have[i] = 0; } } vector<ll>res; for (int i = last; i; i--) { if (have[i])res.push_back(i); } cout << res.size() << endl; for (auto v : res)cout << v << ' '; /* ll real_ans; out >> real_ans; cout << real_ans << ' ' << ans << endl; if (real_ans != ans) { cout << n << endl; for (int i = 1; i <= n; i++) cout << vec[i] << ' '; cout << endl; cout << ans << ' ' << real_ans; return 0; } in.close(); out.close(); } */ } /* */
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 62 63 64 65 66 67 68 69 | #include <bits/stdc++.h> typedef long long ll; using namespace std; const ll inf = 1e18 + 7; const ll mod = 1e9 + 7; ll n , m , k , ans = 0 , q; // ifstream in , out; int main() { ios_base::sync_with_stdio(0); cin.tie(0); /* for (int t = 5; t < 1000; t++) { string sin = "orn" , sout = "orn" , st = ""; ll kop = t; while (kop > 0) { st += char(kop % 10 + 48); kop /= 10; } if (st.size() == 0)st = "0"; reverse(st.begin() , st.end()); sin += st; sout += st; sin += ".in"; sout += ".out"; cout << sin << endl; in.open(sin); out.open(sout); */ cin >> n; ll s = 0 , last; for (int ch = 1; ch <= 1000000; ch++) { ll cur = __builtin_popcount(ch); if (s < n) { s += cur; last = ch; } else { break; } } ll need = s - n; vector<bool>have(last + 5 , 1); for (int i = last - 1; i; i--) { ll cur = __builtin_popcount(i); if (cur <= need) { need -= cur; have[i] = 0; } } vector<ll>res; for (int i = last; i; i--) { if (have[i])res.push_back(i); } cout << res.size() << endl; for (auto v : res)cout << v << ' '; /* ll real_ans; out >> real_ans; cout << real_ans << ' ' << ans << endl; if (real_ans != ans) { cout << n << endl; for (int i = 1; i <= n; i++) cout << vec[i] << ' '; cout << endl; cout << ans << ' ' << real_ans; return 0; } in.close(); out.close(); } */ } /* */ |