Description

Recently Luba learned about a special kind of numbers that she calls
beautiful numbers. The number is called beautiful iff its binary
representation consists of k + 1 consecutive ones, and then k
consecutive zeroes.

Some examples of beautiful numbers:

12 (110); 1102 (610); 11110002 (12010); 1111100002 (49610). More
formally, the number is beautiful iff there exists some positive
integer k such that the number is equal to (2k - 1) * (2k - 1).

Luba has got an integer number n, and she wants to find its greatest
beautiful divisor. Help her to find it!

Input

The only line of input contains one number n (1 ≤ n ≤ 105) — the
number Luba has got.

Output

Output one number — the greatest beautiful divisor of Luba’s number.
It is obvious that the answer always exists.

Examples

input

3

output

1

input

992

output

496

思路

题目中定义了一种数,叫做美丽的数,定义是这样的:

一个数的二进制如果有连续的k+1k+1个1和k<script type="math/tex" id="MathJax-Element-139">k</script>个0组成,那么这个数是美丽的数

比如,当:

  • k=0 :1
  • k=1 :110
  • k=2 :11100
  • k=3 :1111000

题目给出了一个数n,让你从它的因子里面找出一个最大的美丽的数

枚举美丽的数,然后与判断是否可以整除

代码

c++:

#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
int dec(string s)
{int len=s.length(),ans=0;for(int i=0; i<len; i++)ans+=(s[i]-'0')*(int)pow(2,len-1-i);return ans;
}
int main()
{int n,p=1;string i="110";scanf("%d",&n);while(dec(i)<=n){if(n%dec(i)==0)p=dec(i);i="1"+i+"0";}printf("%d\n",p);return 0;
}

python3:

n=int(input())
i = '110'
p=1
while int(i,2)<=n:if n%int(i,2)==0:p=int(i,2)i='1'+i+'0'
print(p)

CodeForces - 893B Beautiful Divisors(数学,二进制)相关推荐

  1. CodeForces 893B Beautiful Divisors (打表)

    题目大意:最近,Luba了解了一种特殊的数字,他称之为"漂亮的数字".这个数被称为漂亮是因为它的二进制表示包括k+1个连续的,然后是k个连续的0. Some examples of ...

  2. 893B. Beautiful Divisors#美丽的因子(打表法)

    题目出处:http://codeforces.com/problemset/problem/893/B 题目大意:找到一个数在二进制下,最大的以k个连续的1和k-1个连续的0组成的数字作为因子 #in ...

  3. 【CodeForces 1265C --- Beautiful Regional Contest】

    [CodeForces 1265C --- Beautiful Regional Contest] 题目来源:点击进入[CodeForces 1265C - Beautiful Regional Co ...

  4. B - Beautiful Divisors CodeForces - 893B

    Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number i ...

  5. 【CodeForces - 485C】Bits (二进制相关,数学,贪心)

    题干: Let's denote as  the number of bits set ('1' bits) in the binary representation of the non-negat ...

  6. K-th Beautiful String CodeForces - 1328B(二分+数学)

    For the given integer n (n>2) let's write down all the strings of length n which contain n−2 lett ...

  7. CodeForces - 55D Beautiful numbers

    题目链接:http://codeforces.com/problemset/problem/55/D 题意:求区间[L,R]有多少个Beautiful numbers.Beautiful number ...

  8. Codeforces1600数学day5[找规律CodeForces - 1059C,贪心数学A - Banh-mi CodeForces - 1062C ]

    A - Banh-mi CodeForces - 1062C 题目大意:就是开始给你一个01序列,和q次询问,每次询问会给你一个区间,每次你会从这个区间内拿出一个数,在区间内的其他未被拿走的数字会加上 ...

  9. CodeForces - 364A Matrix(思维+数学)

    题目链接:点击查看 题目大意:给出一个长度为 n 的,只由十进制数字组成的字符串 s,可以构造出一个大小为 n * n 的矩阵,构造方法如下:b[ i ][ j ] = s[ i ] * s[ j ] ...

最新文章

  1. malloc一次性最大能申请多大内存空间
  2. java度量页面_JAVA Metrics 度量工具使用介绍1
  3. 计算机网络 实验六 静态路由配置,《计算机网络》实六 静态路由配置 实验报告.doc...
  4. 未来已来——工作空间WorkSpace和物联网IoT (3)
  5. 云计算大会有感—MapReduce和UDF
  6. 【c++】28.虚析构函数、纯虚函数
  7. php字符串对象,PHP字符串到对象名称
  8. js三元判断html,JS 三元条件运算符
  9. 百度论文引用网络节点分类比赛
  10. Lotus Sametime Server R8.x 标准版部署排错
  11. GID绘图和CDC类
  12. GNURadio For Windows编译安装脚本v1.1.1发布
  13. 数学建模之倾倒的啤酒杯
  14. js 设置cookie
  15. Unicode 字符集
  16. c语言实现 字符串替换函数,C语言函数实现 字符串替换
  17. 快速排序C语言代码+辅助图+注释
  18. 谷歌地图api根据经纬度查询地名php,在线查询经纬度 google map查询地名返回经纬度 geocode geocoder的完整实例 代码下载...
  19. 调整计算机繁体,在线繁体转换
  20. 2015中兴笔试+面试

热门文章

  1. kafka-我与面霸的三百回合大战
  2. 75v5等客制化蓝牙键盘及其它设备重新连接问题
  3. vue微信公众号页面分享
  4. 中集集团高科技中集飞瞳智能铁路货运方案,箱信息箱况自动识别,地点+箱况上报,提升海运铁路数字化管理,智能化铁路货运智能化多式联运
  5. 牛刀:2010年上海房价第一个开始下跌
  6. 丝素蛋白@ZIF8核壳结构纳米微球|AuNPs@ZIF8|ZIF-8@Ag/MWCNTs|ZIF-8包裹的纳米颗粒定制服务
  7. layuitable设置默认选中
  8. chart.js 图表刷新_Chart.js的花式,响应式图表
  9. 1. Qt Designer Studio界面介绍
  10. linux的wps文件怎么看,WPS Office for linux快速入门指南