LuoguP2759 奇怪的函数

LuoguP2759 奇怪的函数

题面

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

 题解

这道题并没有想出来,太丢脸了

 

首先注意到题目要求位数超过N位数字

 

考虑如何求位数,我们发现对于数N的位数就是log10(N)+1

 

换到这道题里就是求log10(x^x)+1>n的最小值的x

 

于是就是x*log10(x)+1>n的最小x值,二分即可

 

#include<bits/stdc++.h>

#define LL long long

using namespace std;

inline LL read()
{
    LL f = 1 , x = 0;
    char ch;
    do
    {
        ch = getchar();
        if(ch=='-') f=-1;
    } while(ch<'0'||ch>'9');
    do
    {
        x=(x<<3) + (x<<1) + ch - '0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*x;
}

int n;
int ans;

int main()
{
    n = read();
    long long  l = 1,r = n;
    while(l<=r)
    {
        long long mid = (l+r)>>1;
        long long res = mid *(log10(1.0*mid))+1;
        if(res  >= n)  ans = mid,r = mid-1;
        else l = mid + 1;
    }
    cout << ans << endl;
}

 

 

posted @ 2020-02-29 23:57  wlzs1432  阅读(140)  评论(0编辑  收藏  举报