此题要用到__int128,不然会溢出。或者用除法的一种题解方式...
博客代码while循环退出条件写错,应该是l <= r......WA了半天才发现
注意:可以用循环乘代替pow,避免使用double。
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef unsigned long long ll;
typedef __int128 it;
int a,b;
ll k;
bool judge(ll x)
{
it ans = 1;
for(int i = 0; i < a; i++)
{
ans *= x;
if(ans > k) return 0;
}
it t = (it)ceil(log2(x));
for(int i = 0; i < b; i++)
{
ans *= t;
if(ans > k) return 0;
}
if(ans > k) return 0;
else return 1;
}
int main()
{
int t;
cin >> t;
while(t--)
{
cin >> a >> b >> k;
ll l = 1, r = 1e18;
ll mid;
ll ans;
while(l < r)
{
// cout<<l<<' '<<r<<endl;
mid = (l+r) / 2;
if(judge(mid))
{
l = mid + 1;
ans = mid;
}
else
r = mid - 1;
}
cout << ans << endl;
}
return 0;
}