Codeforces Educational Codeforces Round 33 B 893B Beautiful Divisors
2017-11-24 22:46
459 查看
B. Beautiful Divisors
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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 ≤ 10^5) — 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+1个1和K个0组成,问给出的n能否整除这种数字,并选出最大的。
思路:把10^5以内的所有这种数字列出出来,然后一个一个的判断,并找出最大值
我这里用的是pow()函数,但是,如果,n的上限再大几个次方的话,最好用一下快速幂,以免tle
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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 ≤ 10^5) — 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+1个1和K个0组成,问给出的n能否整除这种数字,并选出最大的。
思路:把10^5以内的所有这种数字列出出来,然后一个一个的判断,并找出最大值
#include<bits/stdc++.h> using namespace std ; int num[10] ; int main() { for(int i = 1 ; i <= 9 ; i ++) { num[i] = (pow(2 , i) - 1) * pow(2 , i - 1) ; } int n ; cin >> n ; int ans ; for(int i = 1 ; i <= 9 ; i ++) { if(n % num[i] == 0) { ans = num[i]; } } cout << ans << endl ; return 0 ; }
我这里用的是pow()函数,但是,如果,n的上限再大几个次方的话,最好用一下快速幂,以免tle
相关文章推荐
- Educational Codeforces Round 33 (Rated for Div. 2) B - Beautiful Divisors
- 【 Educational Codeforces Round 33 A】Chess For Three
- Educational Codeforces Round 33
- Educational Codeforces Round 33 (Rated for Div. 2) C - Rumor
- Educational Codeforces Round 33 (Rated for Div. 2) D题. Credit Card(贪心)
- Codeforces Educational Codeforces Round 33 C 893C Rumor(并查集)
- Educational Codeforces Round 33 D. Credit Card
- 【Educational Codeforces Round 33】 C. Rumor (并查集)
- Educational Codeforces Round 33 (Rated for Div. 2) 题解
- Educational Codeforces Round 33 (Rated for Div. 2)A-F
- 【Educational Codeforces Round 33】 D. Credit Card (贪心)
- Educational Codeforces Round 33 (Rated for Div. 2)A-F
- Educational Codeforces Round 33 (Rated for Div. 2) A题. Chess For Three
- Educational Codeforces Round 33 F. Subtree Minimum Query
- Educational Codeforces Round 33 (Rated for Div. 2) A-C题解
- 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 B】Beautiful Divisors
- Educational Codeforces Round 33 (Rated for Div. 2) F. Subtree Minimum Query (线段树)
- 【Educational Codeforces Round 33 A】Chess For Three