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.
题意:让你求n^n的最高位;
题解:因为y=x^x该函数是爆炸性增长,而且题目给的范围还特别大,所以我们应该用log10这个函数;
因为 NN=10N*lgN然而比方说指数位置为3.5,那么该函数的最高位就取决于100.5;因此我们只需要把100.5算出来就好了,AC代码如下;
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
using namespace std;
string str1;
int main()
{
double n;
while(~scanf("%lf",&n))
{
double a=n*log10(n);//相当于10^3.5
long long b=(n*log10(n));//相当于10^3;
double c=pow(10,a-b);
c=floor(c);
printf("%.0lf\n",c);
}
return 0;
}