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;
}