hdu-1060(数学问题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1061

思路:结论:a=10^(N*lg(N) - [lg(N^N)]);

证明:如果一直a是结果,则a*10^x=n^n;

对等式两端去对数 lg(a*10^x)=lg(n^n);

x+lga = n*lgn;

所以:a=10^(n*lgn-x);

只要再求出x就可以了,x是n^n的位数,因此,x=[lg(n^n)],[ ]表示向下取整。

所以 a=10^(N*lg(N) - [lg(N^N)]);

参考文章:https://blog.csdn.net/zy691357966/article/details/39718037

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long LL;
int main(void)
{
    int t;
    LL n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lld",&n);
        double tp=1.0*n*log10(1.0*n);
        tp=tp-(LL)tp;
        int ans=(int)(pow(10,tp));
        printf("%d\n",ans);
    }
    return 0;
} 

猜你喜欢

转载自www.cnblogs.com/2018zxy/p/9751259.html
今日推荐