您的位置:首页 > 其它

1060—Leftmost Digit

2013-05-05 21:29 232 查看
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1060

收获:计算N^N结果的最左边的数

由sum=N^N,两边对10取对数,log10(sum)=Nlog10(N),有sum=10^(Nlog10(N));

sum=10^(整数+小数)=10^整数*10^小数;

由于10的整数次幂首位均为1,则仅需考虑Nlog10(N)的结果的小数部分,取整即为最左边的数

int n;

double k=(double)n;

我的代码:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main()
{int t;
__int64 n;
scanf("%d",&t);
while(t--)
{scanf("%I64d",&n);
int uu;
uu=(int)pow(10.0,n*log10((double)n)-(__int64)(n*log10((double)n)));
printf("%d\n",uu);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: