uva 113 Power of Cryptography
2013-09-24 09:57
323 查看
二分法,不多说了,一开始在纠结大数字该怎么办,后来发现32bit环境下double最大值是1.7e+308,完全够用了。
#include <stdio.h> #include <float.h> #include <math.h> int func(double n, double p) { int l, r, m; double v; l = 1; r = 1000000000; while(1) { m = (l+r)/2; v = pow(m, n); if(fabs(v-p)< 1e-9) return m; else { if(v > p) r = m+1; else l = m-1; } } } int main(void) { double n, p; while(scanf("%lf %lf", &n, &p) != EOF) { printf("%d\n", func(n,p)); } return 0; }
相关文章推荐
- UVa-113-Power of Cryptography
- UVA-113 Power of Cryptography
- Uva 113 Power of Cryptography
- Uva 113 - Power of Cryptography
- UVa-113-Power of Cryptography
- UVA 113 Power of Cryptography
- UVA - 113 Power of Cryptography
- UVa 113 Power of Cryptography
- uva - 113 - Power of Cryptography
- UVa 113 Power of Cryptography
- UVA - 113 Power of Cryptography (大数幂+二分)
- UVa 113: Power of Cryptography
- uva 113 Power of Cryptography
- UVa 113|Power of Cryptography|牛顿迭代法|pow函数的应用
- UVA 113 (暑假-数学-A - Power of Cryptography)
- UVA - 113 - Power of Cryptography
- UVA 113-Power of Cryptography(二分+double处理大数据)
- UVa 113 Power of Cryptography
- UVA 113 - Power of Cryptography(数学)
- Power of Cryptography(POJ-2109 && UVA-113)