Educational Codeforces Round 33 (Rated for Div. 2) B. Beautiful Divisors【进制思维/打表】
2 seconds
256 megabytes
standard input
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!
The only line of input contains one number n (1 ≤ n ≤ 105) — the number Luba has got.
Output one number — the greatest beautiful divisor of Luba's number. It is obvious that the answer always exists.
3
1
992
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 ;
}
Educational Codeforces Round 33 (Rated for Div. 2) B. Beautiful Divisors【进制思维/打表】的更多相关文章
- Educational Codeforces Round 37 (Rated for Div. 2)C. Swap Adjacent Elements (思维,前缀和)
Educational Codeforces Round 37 (Rated for Div. 2)C. Swap Adjacent Elements time limit per test 1 se ...
- Educational Codeforces Round 33 (Rated for Div. 2) E. Counting Arrays
题目链接 题意:给你两个数x,yx,yx,y,让你构造一些长为yyy的数列,让这个数列的累乘为xxx,输出方案数. 思路:考虑对xxx进行质因数分解,设某个质因子PiP_iPi的的幂为kkk,则这个 ...
- Educational Codeforces Round 33 (Rated for Div. 2) F. Subtree Minimum Query(主席树合并)
题意 给定一棵 \(n\) 个点的带点权树,以 \(1\) 为根, \(m\) 次询问,每次询问给出两个值 \(p, k\) ,求以下值: \(p\) 的子树中距离 \(p \le k\) 的所有点权 ...
- Educational Codeforces Round 33 (Rated for Div. 2) 题解
A.每个状态只有一种后续转移,判断每次转移是否都合法即可. #include <iostream> #include <cstdio> using namespace std; ...
- Educational Codeforces Round 33 (Rated for Div. 2)A-F
总的来说这套题还是很不错的,让我对主席树有了更深的了解 A:水题,模拟即可 #include<bits/stdc++.h> #define fi first #define se seco ...
- Educational Codeforces Round 33 (Rated for Div. 2) D. Credit Card
D. Credit Card time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Educational Codeforces Round 33 (Rated for Div. 2) C. Rumor【并查集+贪心/维护集合最小值】
C. Rumor time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- Educational Codeforces Round 33 (Rated for Div. 2) A. Chess For Three【模拟/逻辑推理】
A. Chess For Three time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Educational Codeforces Round 33 (Rated for Div. 2)
A. Chess For Three time limit per test 1 second memory limit per test 256 megabytes input standard i ...
随机推荐
- 剑指Offer - 九度1504 - 把数组排成最小的数
剑指Offer - 九度1504 - 把数组排成最小的数2014-02-06 00:19 题目描述: 输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个.例如输 ...
- CodeIgniter学习笔记二:CI中的query_builder(AR)、连贯操作
一.开启query_builder 在application\config\database.php中添加如下代码(默认已开启): $query_builder = TRUE; 二.查询数据 //ge ...
- Django 运行 端口被占用 Error: That port is already in use
本来运行项目:python manage.py runserver 8000 发现运行到结果报错: Error: That port is already in use 首先查看已存在端口号列表: $ ...
- [译]16-spring基于注解的配置元数据
从spring2.5起spring框架开始支持java注解的配置元数据.所以除了使用xml配置文件来描述bean的装配之外,你还 可以使用基于java注解的配置元数据来完成同样的功能. spring框 ...
- 【志银】Dev-Cpp配置OpenGL图形库(成功版本:Dev-Cpp 5.7.1 MinGW 4.8.1)
★配置前须知:Dev-Cpp自带OpenGL的使用和OpenGL简介 (附Dev-Cpp下载地址:http://sourceforge.net/projects/orwelldevcpp/?sourc ...
- UVa 1445 - Cubist Artwork
统计正面看高度为i的竖条个数为cnt1[i], 统计侧面看高度为i的竖条个数为cnt2[i]: ans = sum( i * max( cnt1[i], cnt2[i] ) ); ( 1 <= ...
- 滚动数组要来回赋初值呀。。orzzzzzzzzzzzzzzzzzzzzzzzzzz
2个小时的人参orzzzzzzzzzzzzzzz ……~(-o ̄▽ ̄)-o ...……o-(_△_o-) ~...……~(-o ̄▽ ̄)-o ...……o-(_△_o-) ~... ……~(-o ̄▽ ̄) ...
- hihoCoder 1403 后缀数组一·重复旋律(后缀数组+单调队列)
#1403 : 后缀数组一·重复旋律 时间限制:5000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi平时的一大兴趣爱好就是演奏钢琴.我们知道一个音乐旋律被表示为长度为 N 的数构成 ...
- GYM - 101620 J.Justified Jungle
题意: 给出一棵树,删掉其中一些边,要求生成的每个子树节点数一样.输出所有可以删掉的边数. 题解: 以节点1为根,预处理每个子树的大小.对于每个n的因数x,还需满足子树为他倍数的点够n/x个,那么删的 ...
- 洛谷 P2197 【模板】nim游戏 解题报告
P2197 [模板]nim游戏 题目描述 甲,乙两个人玩Nim取石子游戏. nim游戏的规则是这样的:地上有n堆石子(每堆石子数量小于10000),每人每次可从任意一堆石子里取出任意多枚石子扔掉,可以 ...