Educational Codeforces Round 33 (Rated for Div. 2) B题

时间:2019-09-12 13:09:59   收藏:0   阅读:97

B. Beautiful Divisors

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.

Input

3

Output

1

思路:看了看数据范围。QAQ,发现可以打表===水过

AC代码:

 1 #include<bits/stdc++.h>
 2 
 3 using namespace std;
 4 int arr[]={1,6,28,120 ,496 ,2016, 8128,32640, 130816 ,523776}; 
 5 int main(){
 6     int n;
 7     cin>>n;
 8     for(int i=9;i>=0;i--){
 9         if(arr[i]>n)
10             continue;
11         if(arr[i]==n){
12             printf("%d",n);return 0;
13         }
14         if(n%arr[i]==0){
15             cout<<arr[i];return 0;
16         }
17     }
18     return 0;
19 } 

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!