acm课-求n^n的最左边的数字

来源:互联网 发布:阿里云计算是什么 编辑:程序博客网 时间:2024/06/07 03:00

技巧题,陈宇老师不愧是数学系出身,果然很牛,尤其记得大二他给队伍讲高斯消元,好像没人听得懂,。。。。
方法,先取log,然后在将整数部分减掉。

#include <iostream>#include <cstdlib>#include <cstdio>#include <cmath>using namespace std;int main(){   int n;   int t;   cin>>t;   while(t--)   { cin>>n;    double x=n*log10((double)n);    x-=(long long)x;    x=(int)pow(10,x);    printf("%.0lf\n",x);   }    return 0;}
0 0