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...

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 

 

目录
相关文章
|
Java 人工智能
HDU1421
                       搬寝室 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem Description 搬寝室是很累的,xhd深有体会.时间追述2006年7月9号,那天xhd迫于无奈要从27号楼搬到3号楼,因为10号要封楼了.看着
1300 0
|
机器学习/深度学习
|
机器学习/深度学习 算法
|
人工智能 Java
HDU 1081
To The Max Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5027 Accepted Submission(s): 2388 Pr...
813 0
|
Java
HDU 1846(巴什博弈)
Brave Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4050    Accepted Submission(s): 2644 Problem Description 十年前读大学的时候,中国每年都要从国外引进一些电影大片,其中有一部电影就叫《勇敢者的游戏》(英文名称:Zathura),一直到现在,我依然对于电影中的部分电脑特技印象深刻。
804 0
HDOJ(HDU) 1570 A C
Problem Description Are you excited when you see the title “AC” ? If the answer is YES , AC it ; You must learn these two combination formulas in the school .
796 0
|
存储 Java 人工智能
HDU 1496
Equations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3188 Accepted Submission(s): 1247 Pro...
947 0
|
人工智能
HDU 1078
FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2812 Accepted Submission(s):...
898 0

热门文章

最新文章