上述程序为 C++ 代码,其中 count(i) 表示 i 二进制下 1 的个数,例如 count(0) 的返回值为 0,而 count(10001279) 的返回值为 15。
其中count(x)可以使用函数__builtin_popcount(x)解决,或许比while(x) {if (x | 1) cnt++; x >>= 1;}更快?