版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/oidoidoid/article/details/82154311
思路简单,wa题无数遍,哭了
对了个拍,发现log2不可以用log来求,因为不能保证精度,预处理了2的倍数用二分找了。
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<vector>
#include<set>
#include<math.h>
#include<queue>
#include<map>
#include<stack>
#define go(i,a,b) for (int (i)=(a);(i)<=(b);(i)++)
#define ll unsigned long long
using namespace std;
vector<ll>pow2;
void init(){
pow2.push_back(1);
go(i,1,63){
pow2.push_back(pow2[i-1]*2);
}
}
bool check(ll x, ll a, ll b, ll k){
ll tmp=1;
go(i,1,a){
if (tmp<=k/x) tmp*=x;
else return false;
}
ll y=lower_bound(pow2.begin(),pow2.end(),x)-pow2.begin();
//cout<<y<<endl;
if (y==0) return true;
go(i,1,b){
if (tmp<=k/y) tmp*=y;
else return false;
}
//cout<<tmp<<endl;
return true;
}
ll find(ll a, ll b, ll k){
ll l=1,r=1000000000000000000LL;
while (l!=r){
ll m=(l+r)/2+1;
//cout<<m<<" "<<check(m,a,b,k)<<endl;
if (check(m,a,b,k)) l=m;
else r=m-1;
}
return l;
}
int main(){
init();
int T;
ll a,b,k;
scanf("%d",&T);
while (T--){
scanf("%llu%llu%llu",&a,&b,&k);
//cout<<a<<b<<k;
ll ans=find(a,b,k);
printf("%llu\n",ans);
}
}
/*
对拍出错的样例
1
1 5 71700000000033863
*/