uva 113 Power of Cryptography

来源:互联网 发布:日历软件 编辑:程序博客网 时间:2024/05/18 02:28

二分法,不多说了,一开始在纠结大数字该怎么办,后来发现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;elsel = m-1;}}}int main(void){double n, p;while(scanf("%lf %lf", &n, &p) != EOF){printf("%d\n", func(n,p));}return 0;}


 

原创粉丝点击