【问题描述】
使得x^x达到或超过n位数字的最小正整数x是多少?
【输入格式】
输入一个正整数n。
【输出格式】
输出使得x^x达到n位数字的最小正整数x。
【输入样例】
11
【输出样例】
10
【数据范围】
n<=2 000 000 000
题目要求求x^x的位数为n时最小的x,由于一个正整数的位数n=floor(logx+1)(log取常用对数),所以说x^x的位数是floor(log(x^x)+1),由对数运算可知floor(log(x^x)+1)=floor(x*logx+1)。
二分猜x,带入上式检验,如果x^x的为位数大于了n,说明x猜大了,应该在小的部分猜,否则在大的区间猜。最后的答案就是x。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const LL maxn=2000000000;
int n;
double check(LL m)
{
if(m==0)return 0;
return floor((double)m*log10(m)/1.0)+1;
}
int main()
{
scanf("%d",&n);
LL A=0,B=maxn,Ans;
for(int i=0;i<70;i++)//二分猜x
{
LL m=A+B>>1;
if(check(m)>=n)B=m,Ans=B;
else A=m;
}
cout<<Ans<<endl;
return 0;
}