zoukankan      html  css  js  c++  java
  • 【CodeVS】 p1696 奇怪的函数

    题目描述 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 }

     

     

    —Anime Otaku Save The World.
  • 相关阅读:
    2019.4.26 周五 阴转小雨
    2019.4.25 周四 阴有小雨
    2019.4.24 周三 阴
    2019.4.23 周二 阴
    2019.4.22 周一 阴转小雨
    oracle优化(一)
    Opencv-Python学习笔记(二)
    Opencv-Python学习笔记(一)
    XtraGrid实现checkbox全选功能
    XtraGrid中checkbox状态设置
  • 原文地址:https://www.cnblogs.com/DMoon/p/4912457.html
Copyright © 2011-2022 走看看