top1编程
← 返回题目
题解

【基础】A变B

1 条题解

  • 0
    @ 2026-7-29 0:19:29
    #include<cstdio>
    #define LL long long
    //函数功能:求出整数n二进制表示中1的个数
    LL getOneNumber(LL n)
    {
        LL cnt=0;
        while(n)
            n&=n-1,cnt++;
        return cnt;
    }
    int main()
    {
        LL a,b;
        while(~scanf("%lld%lld",&a,&b))
            printf("%lld&#92;n",getOneNumber(a^b));
        return 0;
    }
    
    • 1