首页 > 其他 > 详细

洛谷 P2759 奇怪的函数

时间:2017-09-11 22:25:19      阅读:314      评论:0      收藏:0      [点我收藏+]

题目描述

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

输入输出格式

输入格式:

 

一个正整数 n

 

输出格式:

 

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

 

输入输出样例

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

说明

n<=2000000000

思路:根据换底公式 可以推得,当x*log10(x)==n-1时x^x恰好为n位数,所以二分查找即可,在特判一下为1的情况。

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,mid;
int main(){
    //freopen("Lemon_Soda.in","r",stdin);
    //freopen("Lemon_Soda.out","w",stdout);
    scanf("%d",&n);
    int l=0,r=1000000000,prel,prer;
    if(n==1){
        cout<<1;
        return 0;
    }
    while(l<r){
        prel=l;prer=r;
        int mid=(l+r)/2;
        if(mid*log10(mid)<n-1)    l=mid;
        else if(mid*log10(mid)>n-1)    r=mid;
        if(l==prel&&r==prer)    break;
    }
    cout<<prer;
}

 

洛谷 P2759 奇怪的函数

原文:http://www.cnblogs.com/cangT-Tlan/p/7507019.html

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