Power of Cryptography
题目链接:http://poj.org/problem?id=2109
Description
This problem involves the efficient computation of integer roots of numbers.
Given an integer n>=1 and an integer p>= 1 you have to write a program that determines the n th positive root of p. In this problem, given such integers n and p, p will always be of the form k to the n th. power, for an integer k (this integer is what your program must find).
Input
Output
Sample Input
2 16 3 27 7 4357186184021382204544
Sample Output
4 3 1234
题意:给定N,P,求K,(kn = p)。
题解:1、K<=10^9,二分答案即可。
2、公式两边取对数,nlog(k)=log(p),得k = exp(log(p)/n),所以可以用double直接求答案
AC代码:
#include <iostream>
#include <cmath>
using namespace std;
double n,p;
int main(int argc, char const *argv[])
{
while(cin>>n>>p)
{
cout<<pow(p,1/n)<<endl;
}
return 0;
}
4219



被折叠的 条评论
为什么被折叠?



