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)))
用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; }
相关文章推荐
- zoj 2277 The Gate to Freedom
- ZOJ 2277 The Gate to Freedom(n^n)
- zoj 2277 The Gate to Freedom
- zoj 2277 The Gate to Freedom
- zoj2277 The Gate to Freedom
- 【ZOJ2277】The Gate to Freedom
- ZOJ3582 Back to the Past
- zoj 1074 || poj 1050 To the Max(简单DP)
- TOJ 2010 ZOJ 1074 HDU1081 To The Max /最大子矩阵和
- ZOJ 1074 To the Max (DP)
- ZOJ 1074 To the Max(DP)
- ZOJ 3582 Back to the Past
- poj1122&zoj1053 FDNY to the Rescue!(dijkstra+输出路径)
- HDOJ 1081(ZOJ 1074) To The Max(动态规划)
- ZOJ Problem Set - 1074 To the Max (最大和子矩阵 dp)
- ZOJ 1074 To the Max
- ZOJ 1074 To the Max【DP】【最大子段和】
- HDOJ 1081(ZOJ 1074) To The Max(动态规划)
- ZOJ-1053 FDNY to the Rescue!
- ZOJ 3949 Edge to the Root(树形DP)