* The leftmost number

Source: Internet
Author: User
Tags pow time limit

Problem S
Time limit:1000 MS Memory limit:32 MB 64bit IO Format:%i64d
submitted:61 accepted:25
[Submit] [Status] [Web Board]
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 = leftmost, so the-the-digit is 2.
In the second case, 4 * 4 * 4 * 4 = at the very leftmost digit is 2.

 [CPP] View plain copy on code to view the snippet derivation to my code slice 01./* the idea: 02.1, make m=n^n; 03. 
04.2, the log10 (M) =n*log10 (n), the m=10^ (N*LOG10 (n)), and 05 are taken on both sides of the equivalence. 
06.3, so that n*log10 (N) =a+b,a is an integer, B is a decimal, and 07. 
08.4,c function: log10 (), calculates logarithm, pow (A, b) calculates a^b 09. 
10.5, because 10 of any integer power of the first must be 1, so, the first of M and N*log10 (N) of the small part of the section, 11.    
12. That is, only by seeking 10^b to save; 13. 14.6, the final 10^b rounding, the output of the number of rounding is OK. 
(Because 0<=b<1, so 1<=10^b<10 to 15. 
16. Its rounding, then is a bit, that is, the number of the request).   

17.*/18.//hdoj system is a pit, all kinds of CE, all kinds of WA, thanks to Kangxiaohui guidance.
    #include <stdio.h> #include <math.h> int main () {long n,i,s,m,a;
    scanf ("%i64d", &m);
     for (i=0;i<m;i++) {scanf ("%i64d", &n);
     a= (int) (POW (10,N*LOG10 (n)-(Long Long) (N*LOG10 (n)));
    printf ("%i64d\n", a);
} return 0; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.