codeforces 579A Raising Bacteria

A. Raising Bacteria

You are a lover of bacteria. You want to raise some bacteria in a box.

Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly x bacteria in the box at some moment.

What is the minimum number of bacteria you need to put into the box across those days?

Input

The only line containing one integer x (1 ≤ x ≤ 109).

Output

The only line containing one integer: the answer.

Sample test(s)

Input

5

Output

2

Input

8

Output

1

Note

For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 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.

For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1.

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<algorithm>
 4 using namespace std;
 5 int main()
 6 {
 7     int x,ans=1;
 8     scanf("%d",&x);
 9     while(x!=1)
10     {
11         if(x&1)ans++;
12         x>>=1;
13     }
14     printf("%d\n",ans);
15     return 0;
16 }
时间: 2024-10-27 11:03:04

codeforces 579A Raising Bacteria的相关文章

codeforces #320 div 2A - Raising Bacteria (位运算)

A - Raising Bacteria Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put

codeforces Dima and Bacteria

题意:给出n,m和k,表示有n个细菌,m种仪器和k种细菌,给出k种细菌的数量ci,然后每个细菌按照种类排成一排(所以有第i种细菌的序号从∑(1≤j≤i-1)cj + 1 到∑(1≤j≤i)cj):接下来给出m种仪器,有u,v,x三个值,表示说从可以在第u,v号细菌之间移动能量,代价为x.请帮助判断说这些细菌是否正确,正确的前提条件是说同种细菌之间移动能量为0,如果正确的话,给出两两细菌(种类)间移动能量的最小值. 思路:并差集+floyd: 1 #include <cstdio> 2 #inc

Codeforces Round#320 Div2 解题报告

Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Finding Team Member codeforces 579C A Problem about Polyline codeforces 579D "Or" Game codeforces 579E Weakness and Poorness codeforces 579F LCS Aga

[Codeforces] Round #320 (Div.2)

1.前言 虽然这次我依旧没有参加正式比赛,但是事后还是看了看题目的...一般不怎么刷Codeforces. A.Raising Bacteria You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night

CodeForces Round #320 Div2

A. Raising Bacteria 计算一下x的bitcount就是答案. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 7 int bitcount(int x) 8 { 9 int ans = 0; 10 while(x) 11 { 12 if(x & 1) ans++

【解题报告】CF Round #320 (Div. 2)

Raising Bacteria 题意:盒子里面的细菌每天会数量翻倍,你可以在任意一天放任意多的细菌,最后要使得某天盒子里面的细菌数量等于x,求至少要放多少个细菌 思路:显然,翻倍即为二进制左移一位,那么放入一个细菌,到第二天就变成2个二进制下即为1->10对于任意二进制数 如:1001110,只需要在第一天放1个,第4.5.6天各放一个,再等一天,就可以了.所以答案显然是x在二进制下1的个数. Finding Team Member 题意:2n个人,每两个人组合的队伍有aij的力量.每个人都希

CodeForces 400D (最短路+并查集) Dima and Bacteria

 Description Dima took up the biology of bacteria, as a result of his experiments, he invented k types of bacteria. Overall, there are n bacteria at his laboratory right now, and the number of bacteria of type i equals ci. For convenience, we will

Codeforces Round #125 (Div. 1) A. About Bacteria

Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high. At the beginnin

codeforces 400 D Dima and Bacteria【并查集 Floyd】

题意:给出n个点,分别属于k个集合,判断每个集合里面的点的距离都为0,为0的话输出yes,并输出任意两个集合之间的最短路 这道题目有两个地方不会处理, 先是n个点,分别属于k个集合,该怎么记录下来这里, 然后就是判断每个集合里面的点的距离是否为1,这里可以用并查集来做,如果在输入点的时候,距离为0,就将这两点合并 最后判断每个点,如果他们同属于一个集合,判断它俩的根是否一样就可以了 最后用floyd求最短路 1 #include<iostream> 2 #include<cstdio&g