HDU 1060 Leftmost Digit

http://acm.hdu.edu.cn/showproblem.php?pid=1060

 

题意:

求N^N的首位数字

 

解法:

取对数orz 不然肯定溢出

n=10^x*m => lgn=x+lg(m)

注意用long long取整

 

代码: 0MS  1068K

#include <cstdio>
#include <cmath>
using namespace std;

int main() {
    int t, n;
    scanf("%d", &t);
    while (t--) {
        scanf("%d", &n);
        printf("%d\n", (int)pow(10.0 , (n * log10(n) - (long long)(n * log10(n)))));
    }
    return 0;
}

 

posted @ 2015-02-01 20:21  RSola  阅读(81)  评论(0)    收藏  举报