#include <iostream>
#include <vector>
using namespace std;
int jol(int num){
int digit;
int n = 1;
int sum = 0;
while (num > 0){
digit = num % 10;
num = (num - (num % 10)) / 10;
sum += digit * n;
n *= 2;
}
return sum;
}
int main() {
int n;
cin >> n;
n += 1;
//WEJŚCIE
int k = 0; // dlugosc ciagu
vector<int> kLiczb;
int liczba = 1;
while(1){
if (n == 0){
break;
}
int decimal = liczba, binary = 0, remainder, product = 1;
while (decimal != 0) {
remainder = decimal % 2;
if (remainder == 1){
n--;
if (n == 0){
break;
}
}
binary = binary + (remainder * product);
decimal = decimal / 2;
product *= 10;
}
if (binary != 0) {
kLiczb.insert(kLiczb.begin(), binary);
}
liczba++;
}
k = kLiczb.size();
for (int i = 0; i < k - 1; ++i) {
kLiczb[i] = jol(kLiczb[i]);
}
if (kLiczb[0] <= kLiczb[1] && k > 2){
int t = kLiczb[0];
kLiczb[1] += t;
kLiczb.erase(kLiczb.begin());
k--;
}
cout << k << '\n';
for(int liczba : kLiczb){
cout << liczba << " ";
}
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 | #include <iostream> #include <vector> using namespace std; int jol(int num){ int digit; int n = 1; int sum = 0; while (num > 0){ digit = num % 10; num = (num - (num % 10)) / 10; sum += digit * n; n *= 2; } return sum; } int main() { int n; cin >> n; n += 1; //WEJŚCIE int k = 0; // dlugosc ciagu vector<int> kLiczb; int liczba = 1; while(1){ if (n == 0){ break; } int decimal = liczba, binary = 0, remainder, product = 1; while (decimal != 0) { remainder = decimal % 2; if (remainder == 1){ n--; if (n == 0){ break; } } binary = binary + (remainder * product); decimal = decimal / 2; product *= 10; } if (binary != 0) { kLiczb.insert(kLiczb.begin(), binary); } liczba++; } k = kLiczb.size(); for (int i = 0; i < k - 1; ++i) { kLiczb[i] = jol(kLiczb[i]); } if (kLiczb[0] <= kLiczb[1] && k > 2){ int t = kLiczb[0]; kLiczb[1] += t; kLiczb.erase(kLiczb.begin()); k--; } cout << k << '\n'; for(int liczba : kLiczb){ cout << liczba << " "; } return 0; } |
English