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

洛谷 P2759 奇怪的函数

时间:2017-09-11 23:00:43      阅读:271      评论:0      收藏:0      [点我收藏+]

标签:else   www.   int   span   pac   pen   一个   size   art   

题目描述

使得 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 奇怪的函数

标签:else   www.   int   span   pac   pen   一个   size   art   

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

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