博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF579 - A Raisinng bacteria
阅读量:5013 次
发布时间:2019-06-12

本文共 1648 字,大约阅读时间需要 5 分钟。

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.

题解:水题;

参考代码:

1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 using namespace std;14 typedef long long LL;15 typedef pair
PII;16 #define PI acos(-1)17 #define EPS 1e-818 const int INF=0x3f3f3f3f;19 const LL inf=0x3f3f3f3f3f3f3f3fLL;20 const int maxn=1e5+10;21 22 int main()23 {24 int n;25 while(~scanf("%d",&n))26 {27 int cnt=0;28 for(int t=1;t<=n;t*=2)29 {30 if((t&n)!=0) cnt++,n-=t;31 } 32 printf("%d\n",cnt); 33 }34 return 0;35 }
View Code

 

转载于:https://www.cnblogs.com/songorz/p/9520420.html

你可能感兴趣的文章
python字符串实战
查看>>
wyh的物品(二分)
查看>>
12: xlrd 处理Excel文件
查看>>
综合练习:词频统计
查看>>
中文url编码乱码问题归纳整理一
查看>>
Cesium应用篇:3控件(3)SelectionIndicator& InfoBox
查看>>
58. Length of Last Word(js)
查看>>
前端面试题汇总(持续更新...)
查看>>
如何成为F1车手?
查看>>
QT自定义消息
查看>>
Save (Not Permitted) Dialog Box
查看>>
装饰模式(Decorator)
查看>>
任务13:在Core Mvc中使用Options
查看>>
利用Excel 2010数据透视图实现数字的可视化的图形直观展示
查看>>
Sort Colors
查看>>
iview树的修改某个节点,树刷新后自动展开你刚才展开的所有节点
查看>>
oracle服务起不来以及无法监听问题解决
查看>>
Mvc--Html.ActionLink()的用法
查看>>
delphi 基础书籍推荐
查看>>
《面向对象程序设计》2018年春学期寒假及博客作业总结
查看>>