LUOGU P2759 奇怪的函数

题目描述

使得 x^x 达到或超过 n 位数字的最小正整数 x 是多少?
输入输出格式
输入格式:

一个正整数 n

输出格式:

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

输入输出样例
输入样例#1: 复制

11

输出样例#1: 复制

10

说明

n<=2000000000

解题思路

sb题,数学高中必修一。x^x>=10^(n-1) 化简一下就是 log10 x^x>=n-1
继续化简可以得到 x*log10 x >=n-1 ,然后二分答案。

代码

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>

using namespace std;
typedef long long LL;

LL n;
int l=1,r=1<<30;
int ans;

int main(){
    cin>>n;
    if(n==1) {cout<<1<<endl;return 0;}
    while(l<=r){
        int mid=l+r>>1;
        double x=log10(mid);
        if((double)mid*x>=n-1) {
            ans=mid;
            r=mid-1;
        }
        else l=mid+1;
    }
    cout<<ans<<endl;
    return 0;
}
原文地址:https://www.cnblogs.com/sdfzsyq/p/9676884.html