Educational Codeforces Round 33 (Rated for Div. 2) 893B. Beautiful Divisors
来源:互联网 发布:乐思网络信息采集系统 编辑:程序博客网 时间:2024/06/05 14:50
题意:给你一个N,问N的最大的美丽因子是多少。美丽因子定义为:二进制下有连续的K+1个1和连续的K个0的N的因子(后面又给了一句话太关键了!)更正式的说,这些数字都会有一个正整数k使得这个数字等于(2k - 1) * (2k - 1)。
思路:N<=100000,即k最大为9,所以我们枚举K从9到1,如果(2k - 1) * (2k - 1) 是N的因子那么就输出(2k - 1) * (2k - 1) ,跳出。
#include<bits/stdc++.h>using namespace std;const int MAXN = 1e5 + 5;int n_beautiful(int n){ return (pow(2, n) - 1) * pow(2, n-1);}int main(){int n; while(~scanf("%d",&n)){for(int i = 9; i >= 1; i--){int temp = n_beautiful(i);if(n % temp == 0){printf("%d\n",temp);break;}}}return 0;}
下面附一份当时没认真读题没看到后面那句话的时候写的一份AC代码
#include<bits/stdc++.h>using namespace std;const int MAXN = 1e6 + 5;string two[MAXN];bool vis[MAXN];string ten_two(int n){string s = "";while(n){char c = n % 2 + '0';s.insert(s.begin(),c);n /= 2;}return s;}void init(){memset(vis,0,sizeof(vis));for(int i = 0; i < MAXN; i++){two[i] = ten_two(i);//two[i] is beautiful?int len = two[i].length();if(len % 2 == 1){bool flag = true;for(int j = 0; j <= len / 2; j++){if(two[i][j] == '0') {flag = false;break;}}for(int j = len / 2 + 1; j < len; j++){if(two[i][j] == '1') {flag = false;break;}}vis[i] = flag;}}}int main(){init();int n; while(~scanf("%d",&n)){for(int i = n; i >= 1; i--){if(vis[i] && n % i == 0){printf("%d\n",i);break;}}}return 0;}
阅读全文
0 0
- Educational Codeforces Round 33 (Rated for Div. 2) 893B. Beautiful Divisors
- codeforces Educational Codeforces Round 33 (Rated for Div. 2)B
- Educational Codeforces Round 33 (Rated for Div. 2) B
- Codeforces Educational Codeforces Round 33 B 893B Beautiful Divisors
- 【Educational Codeforces Round 33 B】Beautiful Divisors
- codeforces 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)
- Educational Codeforces Round 33 (Rated for Div. 2) A
- 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) 题解
- Educational Codeforces Round 33 (Rated for Div. 2) F
- 【Educational Codeforces Round 33】 B. Beautiful Divisors (枚举)
- Educational Codeforces Round 33 (Rated for Div. 2) 893A. Chess For Three
- Educational Codeforces Round 34 (Rated for Div. 2) D
- Educational Codeforces Round 34 (Rated for Div. 2)
- Android应用保存图片到系统图库那些事儿
- Tomcat工作原理
- Mac 安装 python3 , pip3 , pygame
- Eclipse连接到MYSQL数据库的操作
- android inflater详解以及源码解析
- Educational Codeforces Round 33 (Rated for Div. 2) 893B. Beautiful Divisors
- php install
- lintcode 6. 合并排序数组
- Java笔记杨枝12.2
- JavaBean之Builder模式
- [USACO1.4]母亲的牛奶Mother's Milk dfs
- HashMap源码剖析
- 小波变换中的信号扩展(延拓)问题
- 分治法的概念以及应用