Description
给你一个数n,求n用二进制表示时,其中1的个数。
Input
有多组测试用例,每组一个n(0<=n<264)。
Output
n的二进制表示中1的个数。
Sample Input
0
2
7
Sample Output
0
1
3
HINT
使用长整形
#include <iostream>
using namespace std;
int main(){
unsigned long long int n;
while(cin>>n){
int i,res=0;
while(n){
i=n%2;
if(n==0&&i==1)
res++;
n=n/2;
if(i&1==1)
res++;
}
cout<<res<<endl;
}
return 0;
}