Hdu-1060-leftmost digit__ Number theory

Source: Internet
Author: User
Problem Description

Given a positive integer N, you should output the leftmost digit of n^n. Input

The input contains several test cases. The ' the ' 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 should output the leftmost digit of n^n. Sample Input

2
3
4 Sample Output

2
2 Hint

In the "the", 3 * 3 * 3 = leftmost digit is 2.
In the second case, 4 * 4 * 4 * 4 = 256, so the leftmost digit is 2.

Find the first digit of the n^n.
Make m=n^n, both sides of the logarithm, get log10 (m) =n*log10 (n)
Get it Again, m=10^ (N*LOG10 (n))
For the integer power of 10, the first digit is 1, so the first digit depends on the decimal part of the N*LOG10 (n)
Code:

 #include <iostream> #include <iomanip> #include <cstdio> #include < cstdlib> #include <string> #include <cstring> #include <cmath> #include <algorithm> #define N
1000010 using namespace std;
    int main () {#ifndef Online_judge freopen ("1.txt", "R", stdin); #endif int n, T;
    Long Long T;
    Double A, B, C;
    Cin >> T;
        while (t--) {cin >> n;
        A = N*LOG10 (n);
        T = (long long) A;
        b = a-t;
    cout << (Long Long) pow (ten, B) << Endl;
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.