leftmost Digit
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 13680 Accepted Submission (s): 5239
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 was a single integer T which is the number of test cases. T test Cases follow.
Each test case is 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 = ISA, so the leftmost digit is 2. In the second case, 4 * 4 * 4 * 4 = at the very leftmost digit is 2.
To the main question: to the positive integer n, ask n^n the leftmost digit is how much.
Analytic: The number theory on the tall, does not have enough to the mathematics IQ. For reference on the idea of online God: A number is the cardinality of each bit by the corresponding weights, such as 123456, the Radix "1" of the weight of 10^5, the Radix "2" of the weight of 10^4 ... so the question requires the highest base. To x^x the logarithm, x* ln (x)/ln (10), it is assumed that the value is X.ABCDEEFG so 10^x is the highest corresponding weight, 10^ 0.ABCDEFG is the highest cardinality. Note that what you get here is not an integer. Because here is the force of the next bit of the value is also converted to the highest level up, which is a bit like the large number, if the system is not satisfied with the forced carry, it is obvious that it will be in the high one decimal rather than a natural integer. Get 10^ 0.ABCDEFG, and then use double floor (double) function to take off the whole to get the highest value size
For more details, see the blog: http://www.cnblogs.com/jackge/archive/2013/01/03/2842830.html
AC Code:
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main () {
// freopen ("In.txt", "R", stdin);
int t, N;
scanf ("%d", &t);
while (t--) {
scanf ("%d", &n);
Double foo = n * log10 (double (n)); Strong
Double ans = foo-floor (foo) required;
printf ("%d\n", (int) POW (10.0, ans));
}
return 0;
}