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.

Examples
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.

题解:题意很简单找2的次方 下面两种方法

解法一:(树状数组)

 #include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
#define lowbit(x) x&(-x)
int main()
{
int n,t;
while(cin>>n){
t=;
while(n){
t++;
n-=lowbit(n);
}
cout<<t<<endl;
}
return ;
}

解法二:(除以二迭代)

 #include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main()
{
int n,t;
while(cin>>n){
t=;
while(n){
if(n&) t++;
n/=;
}
cout<<t<<endl;
}
return ;
}

Codeforces 579A. Raising Bacteria的更多相关文章

  1. CF 579A Raising Bacteria

    题意:细菌爱好者在盒子里面培养细菌.最初盒子是空的,每天可以往盒子里面添加任意数目的细菌,而且每天每个细菌会分裂成两个.在某一时刻要想获得某一数量的细菌,要求最初放置的最少的细菌数目. 思路: 求出 ...

  2. Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] A. Raising Bacteria【位运算/二进制拆分/细胞繁殖,每天倍增】

    A. Raising Bacteria time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. codeforces Dima and Bacteria

    题意:给出n,m和k,表示有n个细菌,m种仪器和k种细菌,给出k种细菌的数量ci,然后每个细菌按照种类排成一排(所以有第i种细菌的序号从∑(1≤j≤i-1)cj + 1 到∑(1≤j≤i)cj):接下 ...

  4. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

  5. [Codeforces] Round #320 (Div.2)

    1.前言 虽然这次我依旧没有参加正式比赛,但是事后还是看了看题目的...一般不怎么刷Codeforces. A.Raising Bacteria You are a lover of bacteria ...

  6. Codeforces__Raising Bacteria

    题目传送门:Raising Bacteria //问题描述:一个盒子里面放一个细菌在一天可以增生两个细菌. 现在已知盒子里面细菌的个数,问你最初放多少个细菌可以增生盒子里面的细菌数量 //输入:盒子中 ...

  7. CodeForces Round #320 Div2

    A. Raising Bacteria 计算一下x的bitcount就是答案. #include <iostream> #include <cstdio> #include & ...

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

    Raising Bacteria 题意:盒子里面的细菌每天会数量翻倍,你可以在任意一天放任意多的细菌,最后要使得某天盒子里面的细菌数量等于x,求至少要放多少个细菌 思路:显然,翻倍即为二进制左移一位, ...

  9. codeforces 400D Dima and Bacteria 并查集+floyd

    题目链接:http://codeforces.com/problemset/problem/400/D 题目大意: 给定n个集合,m步操作,k个种类的细菌, 第二行给出k个数表示连续的xi个数属于i集 ...

随机推荐

  1. MongoDB update修改器 目录

    MongoDB update修改器: 针对Fields的$修改器 $inc $set $unset MongoDB update修改器: 针对Arrays的$修改器 $push $pull $pop ...

  2. IE8“开发人员工具”(下)

    浏览器模式 说白了,就是让用户选择当前页面用何种IE版本去渲染. 文本模式 说起“文本模式”这个名词,这又要回到渲染页面的3种模式了:诡异模式(Quirks mode,也有翻译为兼容模式.怪异模式的) ...

  3. [js] Array.slice和类数组转数组

    a.call(b) 相当于把a方法放到b的原型上(实例私有方法)执行 Array.slice的用途 https://juejin.im/post/5b20b8596fb9a01e8d6a47c0 用法 ...

  4. IOP知识点(3)-Modal.show

    1.position 模态框初始位置.可设为字符串 "左位置 上位置" 或数组 [左位置, 上位置],规则如下: 左位置 可设为 left|center|right 三者之一,上位 ...

  5. JS控制文本框只能输入数字 \保留小数点后两位

    <input type="text" placeholder="保留到小数点后两位" maxlength="200" onkeyup= ...

  6. MySQL数据类型--与MySQL零距离接触 3-2 外键约束的要求解析

    列级约束:只针对某一个字段 表级约束:约束针对2个或2个以上的字段 约束类型是按功能来划分. 外键约束:保持数据一致性,完整性.实现数据表的一对一或一对多的关系.这就是把MySQL称为关系型数据库的根 ...

  7. vue2.0项目中 localhost改成ip地址访问

    这里 你可以写成你的ip  那你的项目只能ip访问了,但是写成0.0.0.0的话 你既可已localhost 访问也可以ip访问 也可以写成 127.0.0.1也可以,也能local访问了和ip访问( ...

  8. 题外话:Lua脚本语言存在的意义

    纯属个人见解. 大致来说:c/c++执行效率高,游戏中一些性能敏感的复杂计算需要用c/c++来实现,防止游戏卡顿和低帧率.这些复杂计算包括战斗逻辑,复杂AI,骨骼动画蒙皮骨骼点的坐标计算等等.但c++ ...

  9. unity3d-角色控制器续

    自学是一个坚持和寂寞的过程,写博客更是一个总结与成长的过程,加油! 角色控制器续 之前学习了角色漫游,但里面有很多效果都不是我想要的.只有自己的动手实践了才能理会其中的奥妙.所以我又琢磨了许久. 为了 ...

  10. 读书笔记_Effective_C++_条款三:尽可能使用const

    const是常量的意思,它可以定义一个不可改变的量,主要用于以下几个地方: 1. 修饰变量,使之不可改变 举个例子: const int var = 3; 此时var的值就不能改变了.也正是因为con ...