#include<iostream> #include<vector> using namespace std; int main() { int n; int wartosc; int k; vector<int> sumy; vector<int> wynik; sumy.push_back(0); cin >> n; for (int i = 1; i < 130001; i++) { wartosc = 0; k = i; while (k > 0) { if (k % 2 == 1) wartosc++; k /= 2; } sumy.push_back(sumy[i-1]+wartosc); } k = 130000; while (k > 0) { if (sumy[k] < n) { wynik.push_back(k + 1); n -= (sumy[k+1]-sumy[k]); } k--; } if (n == 1) wynik.push_back(1); cout << wynik.size()<<"\n"; for (int i = 0; i < wynik.size(); i++) cout << wynik[i] << " "; 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 | #include<iostream> #include<vector> using namespace std; int main() { int n; int wartosc; int k; vector<int> sumy; vector<int> wynik; sumy.push_back(0); cin >> n; for (int i = 1; i < 130001; i++) { wartosc = 0; k = i; while (k > 0) { if (k % 2 == 1) wartosc++; k /= 2; } sumy.push_back(sumy[i-1]+wartosc); } k = 130000; while (k > 0) { if (sumy[k] < n) { wynik.push_back(k + 1); n -= (sumy[k+1]-sumy[k]); } k--; } if (n == 1) wynik.push_back(1); cout << wynik.size()<<"\n"; for (int i = 0; i < wynik.size(); i++) cout << wynik[i] << " "; return 0; } |