Background
It is dark at night.
It is silence at night.
It is she in the dark.
It is she in the silence.
Then a light appeared. A huge gate came into our sights, called
The Gate to Freedom
Problem
There're some words on the gate: "This gate will lead you to freedom. First, you have to open it. I have a problem for you to solve, if you answer it correctly, the gate will open!"
"Tell me, young boy, what is the leftmost digit of N^N?"
Input
This problem contains multiple test cases.
Each test case contains an integer N (N<=1,000,000,000).
Output
For each test case, output the leftmost digit of N^N.
Sample Input
3
4
Sample Output
2
2
Contest: A Great Beloved and My Gate to Freedom
There is a cx, there is a love_cx.
Author: JIANG, Yanyan
Source: JIANG, Yanyan's Contest #2
设n^n = x,两边同时取对数得n*log10(n) = log10(x),取y=n*log10(n),可知y的小数部分即为n^n最高位的对数。
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
long long n;
while( ~scanf("%lld",&n) ){
double ret = n*log10(n) - (int)(n*log10(n));
ret = pow(10,ret);
printf("%d\n",(int)ret);
}
return 0;
}