洛谷OJ - P2759 - 奇怪的函数(二分答案)

题目描述
使得 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;
			else
				l = mid + 1; 
		} 
	
		printf("%d\n",r);
	}
	return 0;
}



  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值