D - Степени двойки

mail@pastecode.io avatar
unknown
c_cpp
6 months ago
398 B
14
Indexable
Never
#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    int p = 1, k = 0;
    while (p * 2 <= n) {
        p *= 2;
        k++;
    }
    
    if (n == 2) {
        cout << 0;
    }
    
    while (p > 1) {
        if (k % 2 == 0) {
            cout << p << " ";
        }
        
        k--;
        p /= 2;
    }
    return 0;
}


Leave a Comment