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 Descriptiongiven A positive integer N, you should output the leftmost digit of n^n.
Inputthe 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).
Outputfor Each test case, you should output the leftmost digit of n^n.
Sample Input
234
Sample Output
HintIn the first case, 3 * 3 * 3 = 4, so the leftmost digit is 2.In the second case, 4 * 4 * 4 * = up, so t He 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 multiplied by the cardinality of each bit by the corresponding weights, for example 123456, the weight of the radix "1" is 10^5, the weight of the radix "2" is 10^4 ... so the question requires the highest cardinality.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, why? 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;}
HDU 1060 Leftmost Digit (number theory)