zoukankan      html  css  js  c++  java
  • Break Number --AtCoder

    题目描述

    Takahashi loves numbers divisible by 2.
    You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.
    Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.
    For example,
    6 can be divided by 2 once: 6 -> 3.
    8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.
    3 can be divided by 2 zero times.

    Constraints
    1≤N≤100

    输入

    Input is given from Standard Input in the following format:
    N

    输出

    Print the answer.

    样例输入

    7

    样例输出

    4

    分析:这题之前理解错题意WA了好几发(辣鸡队友瞎说题意),其实就是找n以内的最大2的平方数。

    #include <iostream>
    #include <string>
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #define range(i,a,b) for(int i=a;i<=b;++i)
    #define rerange(i,a,b) for(int i=a;i>=b;--i)
    #define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
    using namespace std;
    int n,ans,acnt;
    void init(){
        cin>>n;
    }
    void solve(){
        while(n){
            ++ans;
            n>>=1;
        }
        cout<<(1<<(ans-1))<<endl;
    }
    int main() {
        init();
        solve();
        return 0;
    }
    View Code
  • 相关阅读:
    H3C ER6300 + 两台 H3C S5120 组网举例
    H3C S5120-52P-WiNet交换机配置
    H3C S5120清除console口密码
    光纤简介
    Windows server 2008 R2 多用户远程桌面
    AutoIt 软件自动化操作
    windows server 2008 R2 计划任务备份系统
    AD域部署使用bginfo软件
    使用WSL吧
    Could not load file or assembly……
  • 原文地址:https://www.cnblogs.com/Rhythm-/p/9322372.html
Copyright © 2011-2022 走看看