HDU 1060 Leftmost Digit (number theory)

Source: Internet
Author: User

HDU 1060 Leftmost Digit (number theory)

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 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 ).

OutputFor each test case, you shoshould output the leftmost digit of N ^ N.

Sample Input
234

Sample Output
22HintIn 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.






To the positive integer n, ask the number of digits on the leftmost side of n ^ n.


Analysis: The number theory on the tall is really not enough for the IQ of mathematics. The following is a reference to the idea of the online gods:

A number is multiplied by the base number of each digit, for example, 123456. The base number "1" is 10 ^ 5, the Base Value of "2" is 10 ^ 4 ...... therefore, this question requires the base of the highest bit. Take the logarithm of x ^ x to obtain x * ln (x)/ln (10). Assume that the value is X. abcdeefg, then 10 ^ X is the weight corresponding to the highest bit, 10 ^ 0. abcdefg is the base of the highest bit. Note that the result is not an integer. Why? This is because the value of the next bit is forcibly converted to the highest bit. It is a bit like a large number. If it is not in hexadecimal notation, It is forcibly carried, obviously, it will feed a decimal point rather than a Tianjing integer. After obtaining 10 ^ 0. abcdefg, use the double floor (double) function to remove the integer and obtain the maximum value.


See blog: http://www.cnblogs.com/jackge/archive/2013/01/03/2842830.html for details





AC code:

# Include
 
  
# Include
  
   
# Include
   
    
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 )); // convert double ans = foo-floor (foo); printf ("% d \ n", (int) pow (10.0, ans);} 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.