Problem Description
Given a positive integer N, you should output the leftmost digit of n^n. Input
The input contains several test cases. The ' the ' 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 "the", 3 * 3 * 3 = leftmost digit is 2.
In the second case, 4 * 4 * 4 * 4 = 256, so the leftmost digit is 2.
Find the first digit of the n^n.
Make m=n^n, both sides of the logarithm, get log10 (m) =n*log10 (n)
Get it Again, m=10^ (N*LOG10 (n))
For the integer power of 10, the first digit is 1, so the first digit depends on the decimal part of the N*LOG10 (n)
Code:
#include <iostream> #include <iomanip> #include <cstdio> #include < cstdlib> #include <string> #include <cstring> #include <cmath> #include <algorithm> #define N
1000010 using namespace std;
int main () {#ifndef Online_judge freopen ("1.txt", "R", stdin); #endif int n, T;
Long Long T;
Double A, B, C;
Cin >> T;
while (t--) {cin >> n;
A = N*LOG10 (n);
T = (long long) A;
b = a-t;
cout << (Long Long) pow (ten, B) << Endl;
return 0; }