思路:
找规律。
实现:
1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 int n; 6 while (cin >> n) 7 { 8 if (n == 1) { cout << 1 << endl; continue; } 9 int x = 1; 10 while (n >= 4) 11 { 12 for (int i = 1; i <= (n + 1) / 2; i++) 13 { 14 cout << x << " "; 15 } 16 n /= 2; 17 x *= 2; 18 } 19 if (n == 2) { cout << x << " " << x * 2 << endl; } 20 else { cout << x << " " << x << " " << x * 3 << endl; } 21 } 22 return 0; 23 }