Description
给出一整数n,输出n^n的最高位
Input
第一行为用例组数T,每组用例占一行为一整数n
Output
对于每组用例,输出n^n的最高位
Sample Input
2
3
4
Sample Output
2
2
Solution
这道题直接算肯定不行,也不能用快速幂之类的算法,所以只能找公式了,显然n可以表示成此形式,我们要求的即为x
同时我们有,
不妨令
那么则
Code
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
double n;
cin>>n;
double temp=n*(log(n)/log(10.0))-floor(n*(log(n)/log(10.0)));
int ans=(int)(pow(10.0,temp));
cout<<ans<<endl;
}
return 0;
}