L: XueXX and Binary
Description
Input
The first line of input contains the number of test cases T (T<=100). The descriptions of the test cases follow: The first line of each test case contains one integer a (0<a<=1,000,000,000), standing for the number in decimal.
Output
Sample Input
3 1 91 735
Sample Output
1 5 8
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
//平行算法(計算二進制的1 的個數)
int bitcount(unsigned int n)
{
n=(n&0x55555555)+((n>>1)&0x55555555);
n=(n&0x33333333)+((n>>2)&0x33333333);
n=(n&0x0f0f0f0f)+((n>>4)&0x0f0f0f0f);
n=(n&0x00ff00ff)+((n>>8)&0x00ff00ff);
n=(n&0x0000ffff)+((n>>16&0x0000ffff));
return n;
}
int main()
{
int T;
int n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
// cout<<"sdfas";
printf("%d\n",bitcount(n));
}
return 0;
}