[Luogu] P9502 题解

P9502 题解

很简单,循环找到第一个使 \(2^{m}\ge n\) 的偶数 \(m\),因为要求的是偶数,再输出 \(m-2\) 即可。

#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);//加速cin和cout
	cin>>n;
	for(int i=2;;i+=2){
		if(pow(2,i)>=n){
			cout<<i-2;
			return 0;
		}
	}
	return 0;
}
posted @ 2023-11-17 20:34  FurippuWRY  阅读(27)  评论(0)    收藏  举报