幂次进近


ps:萌新第一次写题解,发现用数学的方法也可以过

思路


这题本质是求n两侧的哪一个距离更近 alt 依据此数学公式: alt

向下取整就得到,res+1就是, 现在只需要判断哪一个更接近就好了

代码实现

#include<bits/stdc++.h>
using namespace std;
#define int long long
long double n,k,t;
int res,ans;
signed main(){
    cin>>t;
    while(t--){
        cin>>n>>k;
        res=pow(n,(1/k));
        if(abs(n-pow(res,k))<abs(n-pow(res+1,k))){
            cout<<res<<endl;
        }
        else{
            cout<<res+1<<endl;
        }
    }
    return 0;
}