洛谷 P9502 『MGOI』Simple Round I | A. 魔法数字 の 题解

直接用 pow() 函数暴力判断即可,一旦不符合条件就立即跳出循环,要注意开 long longunsigned long long

#include <iostream>
#include <cmath>
using namespace std;
unsigned long long n, num;
int main(){
    cin >> n;
    for(unsigned long long i = 2; i <= n; i += 2){
        unsigned long long ans = pow(2, i);
        if(ans < n) num = i;
        if(ans >= n) break;
    }
    cout << num;
    return 0;
}

记录

posted @   NFGase  阅读(30)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
  1. 1 世间美好与你环环相扣 柏松
  2. 2 Take Me Hand Cécile Corbel
  3. 3 Teeth 5 Seconds of Summer
  4. 4 So Far Away (Acoustic) Adam Christopher
  5. 5 Counting Stars OneRepublic
  6. 6 Love Story Taylor Swift
  7. 7 Galway Girl MADILYN
  8. 8 Love Is Gone (Acoustic) SLANDER / Dylan Matthew
  9. 9 凄美地 郭顶
  10. 10 East of Eden Zella Day
  11. 11 在你的身边 盛哲
Teeth - 5 Seconds of Summer
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

Not available

点击右上角即可分享
微信分享提示