HDU 1060 Leftmost Digit

题目大意是求出N^N的最高位整数。设M = N ^ N, 则对等式两边同时求lg得, M = 10^(N*lgN),由于10的整数次方的最高位恒为一,故对M的最高位不产生影响,于是对M的最高位产生影响的只有10^(N*lgN的小数部分)。由此分析过后,我们只需要求出N*lgN的小数部分a然后求10^a的整数部分即为M的最高位整数。

AC code:

View Code
 1 #include <iostream>
 2 #include <math.h>
 3 __int64 n;
 4 double temp;
 5 int cas;
 6 using namespace std;
 7 
 8 int main()
 9 {
10     while(scanf("%d", &cas) != EOF)
11     {
12         while(cas--){
13             cin >> n;
14             temp = n * log10((double)n);
15             temp = temp - (__int64)temp;
16             printf("%d\n", (int)pow(10.0, temp));
17 
18         }
19     }
20 }
posted @ 2012-04-24 17:19  背着超人飞  阅读(146)  评论(0)    收藏  举报