您的位置:首页 > 其它

hdu 1060 Leftmost Digit

2013-09-25 23:05 501 查看
题意:求n^n的第一个数字是多少?

题解:c=log10(n^n)=nlog10(n),a是c的整数部分,b是c的小数部分,a+b=c;n^n=10^c=10^a*10^b,所以10^b=10^c/10^a=10^(c-a),

10^b的整数部分是一位,就是答案了。

耗时:0MS

#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL __int64
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        double s;
        int n;
        scanf("%d",&n);
        s=n*log10(1.0*n);
        s-=(LL)s;//强制转换成整数可能会超int
        printf("%d\n",(int)pow(10.0,s));
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: