HDU 1060 Leftmost Digit

  • 2018-08-07
  • 30
  • 0

题目:

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

题目链接

n^n=x

\therefore \log_{10}{n^n}=n\times log_{10}{n}=log_{10}{x}

\therefore x=10^{n \times log_{10}{n}}

n \times log_{10}{n}=a.b,其中a确定了x的位数,b确定了每一位的值。

所以利用10^{b}取整就可以求出第一位数的值。

AC代码:

评论

还没有任何评论,你来说两句吧