• HDU 1060


    Leftmost Digit

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


    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.
     1  //x ^ x= 10^(x*lg(x))=10^(整数部分+小数部分) ;则x ^ x的最高位是由小数部分决定的(因为10的整数次幂不会影响最高位,只在最末位加0)。
     2  //去掉整数部分(floor函数向下去整)得到10^(小数部分)最高位即是所求……
     3  #include <iostream>
     4  #include <cmath>
     5  using namespace std;
     6  
     7  int main()
     8  {
     9      int i,j,k,T;
    10      double ans;
    11      int num;
    12      cin>>T;
    13      while(T--)
    14      {
    15          cin>>num;
    16          ans = log10((double)num);
    17          ans=ans-(int)ans;
    18          ans=ans*num;
    19          ans=ans-(int)ans;
    20          num=(int)pow(10.0,ans);//10的小于1的数次方肯定只有一位 
    21          cout<<num<<endl;
    22      }
    23      return 0;
    24  }
    25  //注意:涉及到数学函数最好g++提交,否则CE 
  • 相关阅读:
    Android Shell命令dumpsys
    查看Android内存的8中方法
    Viewpager 的相关总结
    FileZilla等软件搭建ftp服务器
    Linux系统下邮件服务器的搭建(Postfix+Dovecot)
    PHP 打乱数组
    PHP 日期 加减 月数,天数,周数,小时,分,秒等等
    PHP 常用函数
    111
    phpStudy启动失败提示:缺少VC9运行库
  • 原文地址:https://www.cnblogs.com/hxsyl/p/2671068.html
Copyright © 2020-2023  润新知