您的位置:首页 > 其它

HDU 1060 Leftmost Digit

2012-04-24 17:19 399 查看
题目大意是求出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

#include <iostream>
#include <math.h>
__int64 n;
double temp;
int cas;
using namespace std;

int main()
{
while(scanf("%d", &cas) != EOF)
{
while(cas--){
cin >> n;
temp = n * log10((double)n);
temp = temp - (__int64)temp;
printf("%d\n", (int)pow(10.0, temp));

}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: