思路:水题,就是看二进制有多少个1
#include<bits\stdc++.h>
using namespace std;
int main()
{
int n;
cin >>n;
int ans = 0;
while(n)
{
if(n&1)
ans++;
n>>=1;
}
cout << ans << endl;
}
A. Raising Bacteria
time limit per test
memory limit per test
input
output
You are a lover of bacteria. You want to raise some bacteria in a box.
x
What is the minimum number of bacteria you need to put into the box across those days?
Input
x (1 ≤ x ≤ 109).
Output
The only line containing one integer: the answer.
Examples
input
5
output
2
input
8
output
1
Note
4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
8 in the box. So the answer is 1.