1012 incryptography

1012 Problem M

    Current work incryptography involves (among other things) large prime numbers and computingpowers of numbers among these primes. 

问题:输入两个数n和p,求得k,使得k^n=p。

思路:最初在看到题目时,发现数值较大,很有可能会超出范围,但在查询过几种数据类型的范围后,double却能够表示出题目所给的极限值。

感想:做题过程中,始终都应该多去思考,无疑此题,通过高精度计算,最后同样可以得到结果,但在使用double时,问题就简化了。

#include<iostream>

#include<math.h>

#include<stdio.h>

using namespace std;

int main(){

   double n,p;

   double k;

   while(scanf("%lf%lf", &n, &p) != EOF){

       k=pow(p,1/n);

       cout<<k<<endl;

    }

   return 0;

}

你可能感兴趣的:(1012 incryptography)