Author
Ignatius.L题目大意:1.第一行输入一个整数T代表接下来有T组测试数据。2.接下来的T行,每行输入一个整数(1<=N<=1,000,000,000)。3.输出结果为N^N(N的N次方)最左边的那一位数(即最高位)。4.注意:每行输出一个结果。解题思路:1.令M = N^N2.两边取对数,log10M = N*log10N,得到M = 10^(N*log10N)3.令N^(N*log10N) = a(整数部分) + b(小数部分),所以M = 10^(a+b) = 10^a *10^b,由于10的整数次幂的最高位必定是1,所以M的最高位只需考虑10^b4.最后对10^b取整,输出取整的这个数就行了。(因为0<=b<1,所以1<=10^b<=10对其取整,那么的到的就是一个个位,也就是所求的数)。需要注意的地方:关于取整:可以用强制类型转换(int)10^b,也可以用floor函数floor(10^b),
但要注意的问题是floor函数是double型的,若用floor函数,则在输出时要用"%.0lf\n",
(有关floor函数和ceil函数,详见http://baike.baidu.com/view/2873705.htm)
// hdoj_1060 Leftmost Digit
// 0MS 236K 345 B GCC
#include <stdio.h>
#include <math.h>
int main(void)
{int n, i, ncase;long long x;scanf("%d", &ncase);for(i = 0; i < ncase; i ++){scanf("%ld", &n);double m = n * log10((double)n);double g = m - (long long)m;g = pow(10.0, g);printf("%d\n", (int)g);}return 0;
}
/*求num的最左位上的数:设num=a.~*10^n; a即为所求lg(num)=n+lg(a.~);->:lg(a.~)=lg(num)-n;又n为num的总位数减1,n=(int)lg(num);->:a.~=pow(10,1g(num)-(int)(lg(num)));
*/
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;int main()
{int cas;scanf("%d",&cas);while (cas--){double num;scanf("%lf",&num);double x=num*log10(num);x-=(__int64)x;int ans=pow(10.0,x);printf("%d\n",ans);}return 0;
}