zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 33 (Rated for Div. 2) B. Beautiful Divisors【进制思维/打表】

    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
    3
    output
    1
    input
    992
    output
    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 = 15;
    int n;
    int a[N];
    int main()
    {
        for(int i=1;i<=10;i++) a[i]=(pow(2,i)-1)*pow(2,i-1);
        scanf("%d",&n);
        for(int i=10;i>=1;i--) if(n%a[i]==0) {printf("%d
    ",a[i]);break;}
        return 0;
    }
    View Code
  • 相关阅读:
    Fiddler抓包测试App接口
    APP测试工具之TraceView卡顿检测
    APP弱网测试
    MAT内存问题分析定位
    Android DDMS检测内存泄露
    分库分表之终极设计方案
    反向代理和正向代理
    详解HTTP协议
    Django实现websocket完成实时通讯,聊天室,在线客服等
    分布式全文检索引擎之ElasticSearch
  • 原文地址:https://www.cnblogs.com/Roni-i/p/7890008.html
Copyright © 2011-2022 走看看