zoukankan      html  css  js  c++  java
  • HDU 1060 Left-most Digit

    传送门

    Leftmost Digit

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 15305    Accepted Submission(s): 5937


    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
     
    Solution
    取对数。
    设 n^n = x*10^y(n^n的科学计数法表示),
    则 log (n^n) = y + log x
     
    Implementation
    #include <bits/stdc++.h>
    using namespace std;
    
    int main(){
        int T;
        scanf("%d", &T);
        for(int n; T--; ){
            scanf("%d", &n);
            double t=log10(n)*n;
            printf("%d
    ",(int)pow(10, t-floor(t)));
        }
    }

    Tips

    <cmath>内常用函数:

    pow 

    exp

    log  自然对数

    log10 常用对数

    log2  以2为底的对数

    floor

    ceil

  • 相关阅读:
    LeetCode数据库178
    LeetCode数据库181
    LeetCode数据库177
    LeetCode数据库176
    HNOI2003 消防局的设立
    HNOI2001 产品加工
    Luogu P1020 关路灯
    NOIP2004 虫食算
    SP2713 GSS4-Can you answer these queries IV
    APIO2008 免费道路
  • 原文地址:https://www.cnblogs.com/Patt/p/5003819.html
Copyright © 2011-2022 走看看