Educational Codeforces Round 33 (Rated for Div. 2) B题. Beautiful Divisors
2017-11-24 11:52
411 查看
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
Output
Input
Output
题意:100000 以内 有几个 美丽的数字 , 分别是 :
1(2)->1(10) 110(2)->6(10) 11100(2)->28(10) 1111000(2) -> 120(10) 111110000(2)->496(10) 11111100000(2) -> 2016(10)
1111111000000(2) -> 8128(10) 111111110000000(2) -> 32640(10) 11111111100000000(2) -> 130816(10)
注意看题 , 题目要的是 :“满足 是 n 的 除数 同时 是美丽数字 两个条件的最大数字” ,
View Code
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
题意:100000 以内 有几个 美丽的数字 , 分别是 :
1(2)->1(10) 110(2)->6(10) 11100(2)->28(10) 1111000(2) -> 120(10) 111110000(2)->496(10) 11111100000(2) -> 2016(10)
1111111000000(2) -> 8128(10) 111111110000000(2) -> 32640(10) 11111111100000000(2) -> 130816(10)
注意看题 , 题目要的是 :“满足 是 n 的 除数 同时 是美丽数字 两个条件的最大数字” ,
/* 快速幂判断美丽数字 */ #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std ; #define LL long long // 快速幂 LL pow_x(int k ) { LL result = 1 ; LL a = 2 ; while(k) { if(k&1) { result = result * a ; } a = a*a ; k=k/2 ; } return result ; } int main() { int n ; while(~scanf("%d" , &n)) { bool flag = false ; int result ; for(int i=n ; i>0 ; i--) { for(int k = 1 ; ; k++ ) { if((pow_x(k)-1)*pow_x(k-1) == i ) { if(n%i==0) { result = i ; flag = true ; break ; } } if((pow_x(k)-1)*pow_x(k-1) > i ) { break ; } } if(flag) { break; } } printf("%d\n" , result) ; } return 0 ; }
View Code
相关文章推荐
- Educational Codeforces Round 33 (Rated for Div. 2) A - Chess For Three
- Educational Codeforces Round 33 (Rated for Div. 2) A-C题解
- Educational Codeforces Round 33 (Rated for Div. 2) A题. Chess For Three
- Educational Codeforces Round 33 (Rated for Div. 2) B - Beautiful Divisors
- Educational Codeforces Round 33 (Rated for Div. 2) F - Subtree Minimum Query
- Educational Codeforces Round 33 (Rated for Div. 2) C - Rumor
- Educational Codeforces Round 33 (Rated for Div. 2) D. Credit Card
- Educational Codeforces Round 33 (Rated for Div. 2) C
- Educational Codeforces Round 33 (Rated for Div. 2) D题. Credit Card(贪心)
- codeforces Educational Codeforces Round 33 (Rated for Div. 2)B
- Educational Codeforces Round 33 (Rated for Div. 2) 题解
- Educational Codeforces Round 33 (Rated for Div. 2)
- Educational Codeforces Round 33 (Rated for Div. 2)【C】【并查集】
- Educational Codeforces Round 33 (Rated for Div. 2)
- Educational Codeforces Round 33 (Rated for Div. 2) F. Subtree Minimum Query (线段树)
- Educational Codeforces Round 33 (Rated for Div. 2)A-F
- Educational Codeforces Round 33 (Rated for Div. 2)
- Educational Codeforces Round 33 (Rated for Div. 2)A-F
- Educational Codeforces Round 39 (Rated for Div. 2) 946E E. Largest Beautiful Number
- Educational Codeforces Round 39 (Rated for Div. 2) D. Timetable(动态规划)