Given a positive integer N, you should output the leftmost digit of N^N.
|
Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single positive integer N(1<=N<=1,000,000,000). |
Output
For each test case, you should output the leftmost digit of N^N.
|
Sample Input
2 3 4 |
Sample Output
2 2 |
此题是数论水题,只需要运用对数运算,将n^n,用科学技术法表示然后在对系数取整即可。
#include<iostream>
#include<cmath>
using namespace std;
int n;
int main(){
int a;
long double f;
double x;
while(cin>>n){
while(n-->0){
cin>>a;
f=a*log10(a*1.0)-(long long)(a*log10(a*1.0));
long double d=10;
x=pow(d,f);
cout<<int(x)<<endl;
}
}
return 0;
}