HDU 1016(Leftmost Digit)N^N 最左边的数

Leftmost Digit

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10400    Accepted Submission(s): 3957


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

 

Author
Ignatius.L
 
 
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        __int64 n;
        scanf("%I64d",&n);
        double tem=n*log10(1.0*n)-(__int64)(n*log10(1.0*n));
        double ans=pow(10.0,tem);
        printf("%d\n",(int)ans);
    }
    return 0;
}


感慨一下log10()非常好用
10^(a+b)=n^n
n*log(n)=a+b
b=n*log10(n)-(__int64)(n*log10(n))
10^b 从而表示第一位
n=87455时,a=4,b=0.941784644.
10^a=10000.10^b=8.7455
从别人处引用而来


posted on 2013-05-28 19:34  张狂不年轻°  阅读(262)  评论(0)    收藏  举报