直接用 pow()
函数暴力判断即可,一旦不符合条件就立即跳出循环,要注意开 long long
或 unsigned 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;
}
标签:MGOI,洛谷,题解,unsigned,long,P9502
From: https://www.cnblogs.com/NFGase/p/17699165.html