码迷,mamicode.com
首页 > 其他好文 > 详细

luogu P2759 奇怪的函数 |二分答案

时间:2019-11-13 22:20:43      阅读:77      评论:0      收藏:0      [点我收藏+]

标签:main   string   多少   描述   iostream   line   inline   space   algo   

题目描述

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

输入格式

一个正整数 n

输出格式

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


计算一个数有多少位 log10(x)+1

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
int n;
inline bool check(int x){
    if(x*log10(x)+1<n)return 0;
    else return 1;
}
signed main(){
    cin>>n;
    int l=1,r=n,ans;
    while(l<=r){
        int mid=(l+r)>>1;
        if(check(mid)){
            r=mid-1;
            ans=mid;
        }else{
            l=mid+1;
        }
    }
    cout<<ans<<endl;
}

luogu P2759 奇怪的函数 |二分答案

标签:main   string   多少   描述   iostream   line   inline   space   algo   

原文地址:https://www.cnblogs.com/naruto-mzx/p/11853292.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!