As we known, data stored in the computers is in binary form.(数据以二进制形式存储于电脑之中。)The problem we discuss now is about the positive integers and its binary form.

Given a positive integer I, you task is to find out an integer J, which is the minimum integer greater than I, and the number of '1's in whose binary form is the same as that in the binary form of I.

For example, if "78" is given, we can write out its binary form, "1001110". This binary form has 4 '1's. The minimum integer, which is greater than "1001110" and also contains 4 '1's, is "1010011", i.e. "83", so you should output "83".

#include<iostream>
using namespace std; int count(int n)
{
int res=0;
while(n)
{
res++;
n=n&(n-1);
}
return res;
} int main()
{
int n;
while(cin>>n && n)
{
int cnt=count(n);
while(n++)//自增
{
if(cnt==count(n))
{
cout<<n<<endl;
break;
}
}
}
return 0;
}

  

最新文章

  1. JAVA初学(1):值类型和引用类型的区别
  2. 可能是一场很 IN 的技术分享
  3. 关于img 403 forbidden的一些思考
  4. SQL:认识数据库约束
  5. 使用 Swagger UI 与 Swashbuckle 创建 RESTful Web API 帮助文件
  6. PHP数据库结果集处理
  7. 省选训练赛第4场D题(多米诺骨牌)
  8. 辉哥用的这种方法实现ZABBIX的MYSQL批量监控
  9. Netbeans 注释模板配置
  10. HDU 4333 Revolving Digits 扩展KMP
  11. apache: 503
  12. 关于Object类下所有方法的简单解析
  13. AI书单
  14. Android 8.0+ 通知不显示的适配
  15. (转)Spring Boot(六):如何优雅的使用 Mybatis
  16. sticky footer 模板
  17. 在C#用HttpWebRequest中发送GET/HTTP/HTTPS请求(转)
  18. 利用HOG+SVM实现行人检测
  19. 使用Samba服务程序,让linux系统之间共享文件
  20. shell基础:1.0概述

热门文章

  1. CentOS7安装Python3.6.8
  2. Kali Linux中Chrome浏览器不能启动的问题
  3. Qt获取当前屏幕大小
  4. C语言 杂货整理
  5. PHP MySQLi Prepared Statements Tutorial to Prevent SQL Injection
  6. spring boot的一些常用注解
  7. java通过递归统计文件大小
  8. cocos studio 中交互性
  9. VSCode部署JAVA项目出现The type java.lang.Object cannot be resolved
  10. Android_SQLite简单的增删改查