#include <bits/stdc++.h>
using namespace std;
int suma(int x){
int wyn = 0;
while(x > 0){
wyn += x % 2;
x /= 2;
}
return wyn;
}
int wyn[1000009];
int akt[1000009];
int main(){
ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
int n, ktora, dod = 0;
cin>>n;
for(int i = 1; i <= n; i++){
akt[i] = suma(i);
dod += akt[i];
//czy = true;
if(dod > n){
ktora = i;
break;
}
}
int ile = dod - n, o = 0;
for(int i = ktora; i >= 1; i--){
//cout<<ile_liczb<<" "<<ile<<" ";
if(ile >= akt[i]){
//cout<<"1"<<endl;
ile -= akt[i];
}
else{
//cout<<"2"<<endl;
wyn[o] = i;
o++;
}
}
cout<<o<<endl;
for(int i = 0; i < o; i++){
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 | #include <bits/stdc++.h> using namespace std; int suma(int x){ int wyn = 0; while(x > 0){ wyn += x % 2; x /= 2; } return wyn; } int wyn[1000009]; int akt[1000009]; int main(){ ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); int n, ktora, dod = 0; cin>>n; for(int i = 1; i <= n; i++){ akt[i] = suma(i); dod += akt[i]; //czy = true; if(dod > n){ ktora = i; break; } } int ile = dod - n, o = 0; for(int i = ktora; i >= 1; i--){ //cout<<ile_liczb<<" "<<ile<<" "; if(ile >= akt[i]){ //cout<<"1"<<endl; ile -= akt[i]; } else{ //cout<<"2"<<endl; wyn[o] = i; o++; } } cout<<o<<endl; for(int i = 0; i < o; i++){ cout<<wyn[i]<<" "; } } |
English