B. Beautiful Divisors
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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

【题意】:beautiful数定义:如果该数在二进制下表示由k+1个连续的1个,接着k个连续的0组成,则该数字称为beautiful的。比如:

换句话说,当且仅当存在一些正整数k使得这个 number =  ( 2k - 1 ) * ( 2^(k - 1) ) ,这个number就是beautiful的。现在给你一个number,求它最大beautiful因子。

【分析】:打表得到K为最大9。求最大因子数可以逆向枚举。

【代码】:beautiful numbers表:

void init(){
num[1] = 1 ;
num[2] = 6 ;
num[3] = 28 ;
num[4] = 120 ;
num[5] = 496 ;
num[6] = 2016 ;
num[7] = 8128 ;
num[8] = 32640 ;
num[9] = 130816 ; }
#include <bits/stdc++.h>

using namespace std;
const int N = ;
int n;
int a[N];
int main()
{
for(int i=;i<=;i++) a[i]=(pow(,i)-)*pow(,i-);
scanf("%d",&n);
for(int i=;i>=;i--) if(n%a[i]==) {printf("%d\n",a[i]);break;}
return ;
}

最新文章

  1. 深入理解JavaScript中 fn() 和 return fn() 的区别
  2. 学习web前端开发基础技术需要掌握:HTML、CSS、JavaScript语言
  3. jQuery添加options点击事件并传值
  4. C#开发中Windows域认证登录2016(扩展吉日嘎拉GPM系统V4.2)
  5. SVN 忽略文件但不删除文件
  6. IOS socket开发基础
  7. 如何避免JSP页面自动生成session对象?为什么要这么做?
  8. 存储过程中的where in实现
  9. Python之创建单元素tuple
  10. MySQL对NULL值的处理
  11. iOS开发——An App ID with identifier &quot;*****&quot; is not avaliable
  12. 聊聊 Tomcat 的单机多实例
  13. Salesforce Lightning开发学习(一)Hello World开发实践
  14. LearnOpenGL
  15. 【HDU - 5845】Best Division(xor-trie、01字典树、dp)
  16. js函數
  17. OAuth:Access to shared resources via web applications
  18. OPC Server开发的几大境界
  19. 第六章 memcached剖析
  20. linux进程 kipmi0

热门文章

  1. 关于代码通过API操作阿里云RDS的巨坑
  2. DOS程序员手册(六)
  3. 决策树之CART算法
  4. ExtJs学习之MessAgeBox的使用
  5. JavaWeb笔记(九)Ajax&amp;Json
  6. 推荐系统评测指标--准确率(Precision)和召回率(Recall)、F值(F-Measure)
  7. nyoj 题目36 最长公共子序列
  8. ocrosoft Contest1316 - 信奥编程之路~~~~~第三关 问题 M: 当总统
  9. python os操作
  10. 【Python】- 第一行跟第二行的写法