看题解才会的.
用double来存储~可以有: n^n = x * 10^m
等式两边同时取对数得:n*log10(n) = log10(x) + m
又m为n^n的位数减1,得:m = ( int ) ( log10( n^n ) ) = (int)(n*log10(n))
所以x就求出来了:x = 10^(n*log10(n) - m) = 10^(n*log10(n) - (int)(n*log10(n)))
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
bool readInt(int & x){
char ch;
x = 0;
ch = getchar();
if(ch == EOF)return false;
while(!(ch >= '0' && ch <= '9') && ch != EOF)ch = getchar();
while(ch >= '0' && ch <= '9'){
x = x * 10 + ch - '0';
ch = getchar();
}
return true;
}
int main(){
double n;
int x = 0;
while(readInt(x)){
n = x;
double t = n * log10(n);
printf("%d\n", (int)pow(10.0, t - (int)t));
}
return 0;
}