Problem C
来源:互联网 发布:洗数据 编辑:程序博客网 时间:2024/06/09 23:06
Problem C
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 167 Accepted Submission(s) : 64
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
给定一个正整数N,求最小的、比N的的正整数M,使得M与N的二进制表示中M含有的1比N含有的1多1个。如给定N为78,其二进制表示为1001110,包含4个1,那么最小的比N大的且二进制包括5个1的数是79,其二进制是1001111。
Input
输入一个正整数N(1<=n<=100000).有多个测试用例。
Output
输出对应的M数。
Sample Input
1
Sample Output
3
#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>using namespace std;int A(int x){ int s=0; while(x) { if(x%2==1) s++; x/=2; } return s;}int main(){ int n,m; while(~scanf("%d",&n)) { int y=A(n); for(int i=n;;i++) { if(A(i)>y) { printf("%d\n",i); break; } } } return 0;}
阅读全文
0 0
- Problem C
- Problem C
- Problem C
- Problem C
- Problem C
- Problem C
- Problem c
- Problem C
- Problem C
- Problem C
- Problem C
- Problem C
- Problem-C
- Problem C
- Problem C
- Problem C
- Problem-C
- Problem C
- 几点感想-20170611
- spark源码之sparkEnv(1)RPC通信
- Java实现-打劫房屋2
- 拓扑排序
- leetcode 260. Single Number III
- Problem C
- android开发艺术探索 学习笔记(二) Activity的启动模式
- eclipsed的C/C++环境配置
- Error:SSL peer shut down incorrectly
- C++ 17 —— 纯虚函数
- HTML5 发布测试版本,通过网页在线安装ipa和apkH
- Problem E
- 百度之度度熊想去商场买一顶帽子,商场里有N顶帽子,有些帽子的价格可能相同。度度熊想买一顶价格第三便宜的帽子,问第三便宜的帽子价格是多少?
- 修改PostgreSQL中pg_hba.conf