luogu P2759 奇怪的函数 |二分答案

题目描述

使得 x^x达到或超过 n 位数字的最小正整数 x 是多少?

输入格式

一个正整数 n

输出格式

使得 x^x达到 n 位数字的最小正整数 x


计算一个数有多少位 log10(x)+1

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
int n;
inline bool check(int x){
    if(x*log10(x)+1<n)return 0;
    else return 1;
}
signed main(){
    cin>>n;
    int l=1,r=n,ans;
    while(l<=r){
        int mid=(l+r)>>1;
        if(check(mid)){
            r=mid-1;
            ans=mid;
        }else{
            l=mid+1;
        }
    }
    cout<<ans<<endl;
}

猜你喜欢

转载自www.cnblogs.com/naruto-mzx/p/11853292.html