Thought: At the beginning, I found it very tangled !!
Later, I saw a person's analysis, which was converted in this way.
M = n ^ N; obtain the logarithm of the two sides. log10 (m) = N * log10 (n); then, M = 10 ^ (N * log10 (n ));
Then, for the integer power of 10, the first digit is 1. Therefore, the first digit depends on the decimal part of N * log10 (n ).
In short, log is very powerful. In order to calculate the number of digits of a number, the big integer is converted into an integer within the range, which is an exponential problem.
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 shoshould output the leftmost digit of N ^ N.
Sample Input
234
Sample output
22
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. Code:
# Include <iostream> # include <cmath> using namespace STD; int main () {_ int64 I, T, A, sum; double S, X, N; cin> T; while (t --) {CIN> N; S = N * log10 (n); A = (_ int64) s; X = S-; sum = (_ int64) Pow (10.0, x); cout <sum <Endl;} return 0 ;}