Strange dichotomy of function

Problem Description

So that x ^ x meet or exceed the minimum n-digit positive integers x is the number?

Input Format

Enter a positive integer n (n <= 2000 000 000).

Output Format

So that the output x ^ x minimum positive integer x n digits.

SAMPLE INPUT

11

Sample Output

10

Restrictions and conventions

Time limit: 1s

Space limitations: 128MB

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int n;
int main()
{
    long long r=1000000000,l=1,t;
    cin>>n;
    while(l<r)
    {
        t=(l+r)/2;
        if(t*log10(t)+1>=n) r=t;
        else if(t*log10(t)<n) l=t+1;
    }
    cout<<r;
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/hfang/p/11239880.html