这道题测试数据好水!
查看原帖
这道题测试数据好水!
1673827
xbb130607楼主2025/8/1 18:12

这道题测试数据好水!,这个代码都能拿90分!

#include <iostream>
using namespace std;
int num[10000005] ,maxn;
bool isprime(int n) {
	if(n<=1)
		return false;
	if(n==2 || n==3)
		return true;
	if(n%2 == 0)
		return false;
	if(n%6!=1 && n%6!=5)
		return false;
	for(int j=3 ; j*j<=n ; j+=2) {
		if(n%j == 0)
			return false;
	}
	return true;
}
int main() {
	//输入数据 
	int N,M;
	int cnt=0;
	cin >> N >> M;
	
	
	//如果N到M之间有二的幂,那只用每次除以2,求多少次次等于1就可以了 
	int t=M;
	while(t>1) {
		++ cnt;
		t >>= 1;
	}
	if((1<<cnt) >= N) {
		cout << cnt;
		return 0;
	}
}

顺便提示一下TLE的大佬,在前面加上我这段代码

2025/8/1 18:12
加载中...