-
题目描述
- 使得 x^x 达到或超过 n 位数字的最小正整数 x 是多少? 输入
- 一个正整数 n 输出
- 使得 x^x 达到 n 位数字的最小正整数 x 样例输入
-
11
样例输出
-
10
题目思路
-
将题目翻译成公式即为:x^x >= 10^(n-1) 对两边取对数得到 x*log10(x) >= n-1 那么我们只要枚举 x 得到最小的x即可,由于数据量的问题,我们采用二分法快速找到最小的x。
-
题目代码
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#define LL long long
using namespace std;
int n, x;
int l, r, mid;bool check(int a){return a*log10(a) >= n-1;
}int main(){while(scanf("%d",&n) != EOF){l = 1; r = 1000000000;while(l < r){mid = (l+r) >> 1;if(check(mid))r = mid;elsel = mid + 1; } printf("%d\n",r);}return 0;
}