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

【CodeVS】 p1696 奇怪的函数

时间:2015-10-26 22:38:16      阅读:394      评论:0      收藏:0      [点我收藏+]

标签:

题目描述 Description

    自从得到上次的教训后,John的上课态度认真多了,也变得更爱动脑筋了。今天他又学习了一个新的知识:关于 xk 的位数。

    如果x大于0小于l,那么位数=1+小数部分×k,

    如果x≥l,那么位数=trunc(ln(x)/ln(10)×k)+1+小数部分×k。

    根据这些函数知识,他学会了求xk的位数了。但他又想到了另外一个问题,如果已知位数N,能不能求出使得 xk 达到或超过N位数字的最小正整数x是多少?

输入描述 Input Description

    输入一个正整数n(n≤2000000000)。

输出描述 Output Description

    输出使得 xk 达到n位数字的最小正整数x。

样例输入 Sample Input

    11

样例输出 Sample Output

    10

思路分析:

换底公式:

log(a)(b)=log(c)(b)/log(c)(a)(a,c均大于零且不等于1)

求位数:

位数

=log(x^x)/ln(10)+1 

=x*(log(x)/log(10))

基本二分

Source :

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cmath>
 4 #define n 2000000000
 5 using namespace std;
 6 int main()
 7 {
 8     long long m,l,r;
 9     long long a,w;
10     scanf("%lld",&a);
11     l=1;
12     r=a*3;
13     while (l<r)
14     {
15         //l=1;
16     //    r=n*3;
17         m=(l+r)/2;
18         w=trunc(log(m)/log(10)*m)+1;
19         if (w<a)
20             l=m+1;
21         else
22             r=m;
23     }
24     printf("%lld",l);
25     return 0;
26 }

 

 

 

【CodeVS】 p1696 奇怪的函数

标签:

原文地址:http://www.cnblogs.com/DMonster/p/4912457.html

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