luogu P2759 奇怪的函数 二分答案+数论

题目描述

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

输入输出格式

输入格式:

一个正整数 n

输出格式:

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

输入输出样例

输入样例#1:
11
输出样例#1:
10

说明

n<=2000000000

判断位数important

#include<iostream>
#include<cmath>

using namespace std;

int n;

bool can(int x) 
{
    if(x*(log(x)/log(10))>=n-1)return true;//判断方程
    return false;
}

int findx(int x,int y) 
{ //判断能不能行二分
    int mid=x+(y-x)/2;
    if(y-x<=1)return y;
    if(can(mid))return findx(x,mid);
    return findx(mid,y);
}

int main() 
{
    cin>>n;
    int ans=findx(0,1000000000);
    cout<<ans;//用二分查找实现
    return 0;
}
原文地址:https://www.cnblogs.com/lyqlyq/p/7103324.html