#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; typedef pair<int,int> pii; typedef vector<ll> vl; typedef vector<int> vi; typedef vector<pll> vll; typedef vector<pii> vii; typedef double db; #define pb push_back #define mp make_pair #define all(x) x.begin(),x.end() #define sz(x) (int)x.size() #define BOOST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define st first #define nd second #define FOR(i,s,k) for(auto i=s; i<k; i++) #define ROF(i,s,k) for(auto i=k-1; i>=s; i--) constexpr ll inf = 1e18+1; constexpr ll MAXN = 1e6+5; constexpr ll LOGN = 18; int main() { BOOST; ll n; cin>>n; ll i = 1; ll s = 0; stack<ll> S; bitset<64> B; while(s<n) { B = i; s+=B.count(); S.push(i); i++; } // cout<<i-1<<" "<<s<<endl; vl wyn; while(!S.empty()) { //teraz wypisz element i usuń następne dopóki suma nie spadłaby za nisko ll l = S.top(); S.pop(); B = l; ll pom = B.count(); // cout<<l<<" "<<pom<<" "<<s<<" "<<n<<endl; if(s-pom < n) { wyn.pb(l); n-=pom; } s-=pom; } cout<<sz(wyn)<<"\n"; FOR(i,0,sz(wyn)) cout<<wyn[i]<<" "; }
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 | #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; typedef pair<int,int> pii; typedef vector<ll> vl; typedef vector<int> vi; typedef vector<pll> vll; typedef vector<pii> vii; typedef double db; #define pb push_back #define mp make_pair #define all(x) x.begin(),x.end() #define sz(x) (int)x.size() #define BOOST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define st first #define nd second #define FOR(i,s,k) for(auto i=s; i<k; i++) #define ROF(i,s,k) for(auto i=k-1; i>=s; i--) constexpr ll inf = 1e18+1; constexpr ll MAXN = 1e6+5; constexpr ll LOGN = 18; int main() { BOOST; ll n; cin>>n; ll i = 1; ll s = 0; stack<ll> S; bitset<64> B; while(s<n) { B = i; s+=B.count(); S.push(i); i++; } // cout<<i-1<<" "<<s<<endl; vl wyn; while(!S.empty()) { //teraz wypisz element i usuń następne dopóki suma nie spadłaby za nisko ll l = S.top(); S.pop(); B = l; ll pom = B.count(); // cout<<l<<" "<<pom<<" "<<s<<" "<<n<<endl; if(s-pom < n) { wyn.pb(l); n-=pom; } s-=pom; } cout<<sz(wyn)<<"\n"; FOR(i,0,sz(wyn)) cout<<wyn[i]<<" "; } |