1 solutions

  • 0
    @ 2026-11-15 12:45:10

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    
    
    int lowbit(int x){
        return x&-x;
    }
    
    int solve(int x){
        int ans = 0;
        for (int i = x;i>0;i-=lowbit(i)){
            ans ++;
        }    
        return ans;
    }
    
    int main(){
        long long n,ans = 0,x;
        cin >> n;
        for (int i = 1;i<=n;i++){
            cin >> x;
            ans = solve(x);
            cout << ans << endl;
        }
        
        return 0;
    }
    
    • 1

    Information

    ID
    195
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    10
    Tags
    # Submissions
    1
    Accepted
    1
    Uploaded By