HDU Leftmost Digit

Problem Description

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

c=log10(n^n)=nlog10(n),a是c的整数部分,b是c的小数部分,a+b=c;n^n=10^c=10^a*10^b,所以10^b=10^c/10^a=10^(c-a),

10^b的整数部分是答案。



#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
#define Max int(5e5+10)
int aa[Max];
int main()
{
    int t,n,i,j,c;
    scanf("%d",&t);
    while(t--) 
	{
	    scanf("%d",&n);
	    ll a=n*log10(n); 
	    double b=n*log10(n)-a;
	    printf("%d\n",(int)pow(10.0,b));
	}	
  return 0;	
}

猜你喜欢

转载自blog.csdn.net/pinkair/article/details/80030519