首页 > 其他 > 详细

洛谷P2759 奇怪的函数(log 二分)

时间:2018-07-10 21:11:01      阅读:188      评论:0      收藏:0      [点我收藏+]

题目描述

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

输入输出格式

输入格式:

 

一个正整数 n

 

输出格式:

 

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

 

输入输出样例

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

说明

n<=2000000000

 

比较套路,首先转化一下题面,我们需要找到一个最小的$x$,使得

$x^x > 10^n$

两边同时取$log$

$xlog_{10}x > n - 1$

由于log函数有单调性,因此可以二分$x$

#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<iostream>
#define int long long  
using namespace std;
const int MAXN = 4 * 1e5 + 10, mod =  100003;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < 0 || c > 9) {if(c == -) f = -1; c = getchar();}
    while(c >= 0 && c <= 9) x = x * 10 + c - 0, c = getchar();
    return x * f;
}
main() {
    int l = 0, r = 1LL * 20000000001, ans = -1, N = read();
    if(N == 1) return !printf("1");
    while(l <= r) {
        int mid = l + r >> 1;
        if(mid * log(mid) / log(10) > N - 1) r = mid - 1, ans = mid;
        else l = mid + 1;
    }
    cout << ans;
}

 

洛谷P2759 奇怪的函数(log 二分)

原文:https://www.cnblogs.com/zwfymqz/p/9291192.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!