zoukankan      html  css  js  c++  java
  • HDOJ--ACMSteps--2.1.8--Leftmost Digit-(取对数,数学)

    Problem Description
    Given a positive integer N, you should output the leftmost digit of N^N.
     
    
    Input
    The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
    Each test case contains a single positive integer N(1<=N<=1,000,000,000).
     
    
    Output
    For each test case, you should output the leftmost digit of N^N.
     
    
    Sample Input
    
    2
    3
    4
    
     
    
    Sample Output
    
    2
    2
    
    Hint
    
    In the first case, 3 * 3 * 3 = 27, so the leftmost digit is 2.
    In the second case, 4 * 4 * 4 * 4 = 256, so the leftmost digit is 2.
     
    Author
    Ignatius.L
    

    首先,暴力算是一定会超时的,而且这么大的数也存不下
    这道题运用了取对数来缩小运算范围,
    推导过程如下:
    设M=N^N,则log10(M)=Nlog10(N);
    所以M=10^(N
    log10(N));
    继续转化
    令N=x10^y 例如:155555555=1.5555555510^8;
    M=10^(Nlog10(x10^y)=10^(N(y+log10x))=10^(Ny)*log10x
    so, 只要求出log10x即可
    取整即可

  • 相关阅读:
    Git 的使用
    state介绍
    salt之pillar组件
    salt之grains组件
    python之commands模块
    install命令
    salt常用模块及API
    locate包的安装
    集中化管理平台Saltstack安装配置
    系统批量运维管理器pexpect的使用
  • 原文地址:https://www.cnblogs.com/liuzhanshan/p/5988500.html
Copyright © 2011-2022 走看看