Solutie in C++:
#include <iostream>
int n,r;
int main(int argc, const char * argv[]) {
std::cin>>n;
if (n == 1){
std::cout<<1;
}
else if (2 <= n && n < 4){
std::cout<<1<<" "<<2;
}
else {
r = 2;std::cout<<1<<" "<<2<<" ";
while (r <= n){
r = r * 2;if(r <= n){std::cout<<r<<" ";}
}
}
return 0;
}