- 取余操作可以直接取得是否是1.
- 向右移位操作就是相当于除以2.
#include<bits/stdc++.h> // 万能头文件
using namespace std;
int main(){
int n, res = 0;
cin>>n;
while(n){
if(n%2) res++;
n>>=1;
}
cout<<res<<endl;
return 0;
}
#include<bits/stdc++.h> // 万能头文件
using namespace std;
int main(){
int n, res = 0;
cin>>n;
while(n){
if(n%2) res++;
n>>=1;
}
cout<<res<<endl;
return 0;
}