zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 33 (Rated for Div. 2) B题

    B. Beautiful Divisors

    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.

    Input

    3

    Output

    1

    思路:看了看数据范围。QAQ,发现可以打表===水过

    AC代码:

     1 #include<bits/stdc++.h>
     2 
     3 using namespace std;
     4 int arr[]={1,6,28,120 ,496 ,2016, 8128,32640, 130816 ,523776}; 
     5 int main(){
     6     int n;
     7     cin>>n;
     8     for(int i=9;i>=0;i--){
     9         if(arr[i]>n)
    10             continue;
    11         if(arr[i]==n){
    12             printf("%d",n);return 0;
    13         }
    14         if(n%arr[i]==0){
    15             cout<<arr[i];return 0;
    16         }
    17     }
    18     return 0;
    19 } 
  • 相关阅读:
    如何解决加载动态链接库DLL失败,返回0,GetLastError返回错误码126
    如何实现点击激活窗体同时窗体不跑到最前覆盖其他窗体
    数据库04
    数据库03
    数据库02
    数据库01
    Linux02
    Linux01
    软件质量
    HTML04
  • 原文地址:https://www.cnblogs.com/pengge666/p/11511073.html
Copyright © 2011-2022 走看看