您的位置:首页 > 其它

ZOJ 2277 The Gate to Freedom

2013-05-25 22:03 197 查看
看题解才会的.

用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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: