大佬救命
  • 板块灌水区
  • 楼主Nefertari_fly
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/7/17 14:35
  • 上次更新2024/7/17 15:22:48
查看原帖
大佬救命
1010982
Nefertari_fly楼主2024/7/17 14:35

这是我的代码,答案的第一个数应该是对的,但是后面的部分超时/错误了

#include<bits/stdc++.h>
using namespace std;
int t,l,r;
long long pow(long long a,long long b){
	if(b==0) return 1;
	if(b==1) return a;
	long long ret=pow(a,b/2);
	if(b%2==1) return ret*(ret)*(a);
	return ret*ret;
}
int main(){
	cin>>t;
	while(t--){
		cin>>l>>r;
		int x=l,cnt=0,ans=0;
		while(x<=r){
			x*=2,cnt++;
		}
		for(int i=l;i<=r;i++){
			for(int j=2;;j++){
				int x=cnt-1;
				//cout<<i<<' '<<i*pow(2,(cnt-1))<<endl;
				if(i*pow(j,(cnt-1))<=r) ans++;
				else break;
			}
		}
		cout<<cnt<<' '<<ans<<endl;
	}
	return 0;
}

2024/7/17 14:35
加载中...