// Muzyka pop 2 MUZ; Patryk Grabowski xiv lo
#include <bits/stdc++.h>
using namespace std;
int moc_bitowa(int x) {
int ans = 0;
while(x > 0) {
ans += x % 2;
x /= 2;
}
return ans;
}
//stringstream odp_wzo, odp_brut;
int main_wzo(int n) {
vector<int> odp;
int suma = 0, i = 1, x = 1;
while(suma < n) {
suma += moc_bitowa(i++);
}
i--;
n -= moc_bitowa(i);
odp.push_back(i);
while(n > 0) {
while(suma >= n) {
suma -= moc_bitowa(i--);
}
i++;
n -= moc_bitowa(i);
odp.push_back(i);
i--;
}
cout << odp.size() << '\n';
for(int a : odp)
cout << a << " ";
return 0;
/*
odp_wzo << odp.size() << '\n';
for(int x : odp)
odp_wzo << x << " ";
return 0;
*/
}
int main_brut(int n) {
vector<int> odp;
while(n > 0) {
int suma = 0;
int i = 1;
while (suma < n) {
suma += moc_bitowa(i++);
}
i--;
n -= moc_bitowa(i);
odp.push_back(i);
}
cout << odp.size() << '\n';
for(int x : odp)
cout << x << " ";
return 0;
/*
odp_brut << odp.size() << '\n';
for(int x : odp)
odp_brut << x << " ";
return 0;
*/
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n;
cin >> n;
main_wzo(n);
return 0;
/*
//ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
srand(time(nullptr));
int n;
for(int i = 0; i < 100; i++) {
n = rand() % 100000 + 1;
main_wzo(n);
main_brut(n);
if(odp_wzo.str() != odp_brut.str()) {
cout << n << " zle";
return 0;
}
cout << n << " dobrze \n";
}
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | // Muzyka pop 2 MUZ; Patryk Grabowski xiv lo #include <bits/stdc++.h> using namespace std; int moc_bitowa(int x) { int ans = 0; while(x > 0) { ans += x % 2; x /= 2; } return ans; } //stringstream odp_wzo, odp_brut; int main_wzo(int n) { vector<int> odp; int suma = 0, i = 1, x = 1; while(suma < n) { suma += moc_bitowa(i++); } i--; n -= moc_bitowa(i); odp.push_back(i); while(n > 0) { while(suma >= n) { suma -= moc_bitowa(i--); } i++; n -= moc_bitowa(i); odp.push_back(i); i--; } cout << odp.size() << '\n'; for(int a : odp) cout << a << " "; return 0; /* odp_wzo << odp.size() << '\n'; for(int x : odp) odp_wzo << x << " "; return 0; */ } int main_brut(int n) { vector<int> odp; while(n > 0) { int suma = 0; int i = 1; while (suma < n) { suma += moc_bitowa(i++); } i--; n -= moc_bitowa(i); odp.push_back(i); } cout << odp.size() << '\n'; for(int x : odp) cout << x << " "; return 0; /* odp_brut << odp.size() << '\n'; for(int x : odp) odp_brut << x << " "; return 0; */ } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; main_wzo(n); return 0; /* //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(nullptr)); int n; for(int i = 0; i < 100; i++) { n = rand() % 100000 + 1; main_wzo(n); main_brut(n); if(odp_wzo.str() != odp_brut.str()) { cout << n << " zle"; return 0; } cout << n << " dobrze \n"; } return 0; */ } |
English