# Leftmost Digit

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

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

=log10(n^n)=n*log10(n);所以同样的道理，就可以求这个了.....

``` 1 #include<stdio.h>
2 #include<math.h>
3 int main()
4 {
5     int n,m;
6     scanf("%d",&m);
7     while(m--)
8     {
9         scanf("%d",&n);
10         double a=n*log10(1.0*n);
11         a-=(__int64)a;
12         printf("%d\n",(int)pow(10,a));
13     }
14     return 0;
15 }```

657 篇文章64 人订阅

0 条评论

## 相关文章

### hdu 3948 Portal (kusral+离线)

Portal Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja...

29960

### Ignatius and the Princess II

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth...

13020

### HDUOJ---3371Connect the Cities

Connect the Cities Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768...

33170

### HDU 1796 How many integers can you find(容斥原理)

How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memor...

42750

### HDU 1866 A + B forever!

A + B forever! Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/3...

27950

### HDU 2147 kiki's game(规律，博弈)

kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/10000 ...

28660

### HDUOJ-----(1162)Eddy's picture（最小生成树）

Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/327...

35190

### FZU 2140 Forever 0.5（找规律，几何）

Problem 2140 Forever 0.5 Accept: 371 Submit: 1307 Special Judge Time L...

32640

### HDUOJ---kiki's game

kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/1000 K...

32780

### HDU 5752 Sqrt Bo【枚举，大水题】

Sqrt Bo Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K ...

26840