题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1060
题目大意:求N^N的最高位数字。
关键思想:换底公式使结果变为10^(N*log10(N)),再除以10^(digits-1)就OK了。
代码如下:
//运用换底公式避免幂运算,取整处理。
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int T;
double N;
cin>>T;
while(T--){
cin>>N;
double ans=pow(10,N*log10(N)+1-(double)floor(N*log10(N)+1));
cout<< (floor)(ans)<<endl;
}
return 0;
}
原文:http://www.cnblogs.com/G-M-WuJieMatrix/p/6512117.html