#include <iostream>
using namespace std;
void solve(int x){
    int res = 0;
    while(x){
        if(x&1){
            res++;
        }
        x>>=1;
    }
    cout<<res<<'\n';
}
int main() {
    int a, b;cin>>a>>b;
    solve(a);solve(b);
    return 0;
}
// 64 位输出请用 printf("%lld")

跟快速幂很像,每次左移即可,统计1的个数。

活动地址https://www.nowcoder.com/discuss/726480854079250432