Original question:
Power of cryptography
Background
Cryptography involves (among other things) large prime numbers and computing powers of numbers modulo func tions of these primes. resulted in the practical use of results from number theory and other branches of mathematics once C Onsidered to is of only theoretical interest.
This problem involves the efficient computation of the integer roots of numbers.
The problem
Given an integer n>=1 and an integer p>=1 you is to write a program that determines p√n \sqrt[n]{p}, the positive Nth n^{th} root of P. In this problem, given such integers n and p, p'll always be the of the form kn k^n for a integer k (this integer was what y Our program must find).
The Input
The input consists of a sequence of integer pairs N and p with each integer in a line by itself. For all such pairs 1<=n<=200, 1<=p<= 10101 10^{101} and there exists an integer k, 1<=k<= 109 10^9 such That Kn=p k^n=p.
The Output
The For each integer pair n and p the value P√n \sqrt[n]{p} should is printed, i.e., the number k such that Kn=p k^n=p.
Sample Input
2
16
3
27
7
4357186184021382204544
Sample Output
4
3
1234
English:
give you n and p ask you how much k is. Among them kn=p k^n=p. The range of data is shown in English.
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
Const LL MAXB=POW (10,9);
const double ep=10e-5;
Double n,p,k;
ll Bin_search ()
{
ll l=1,r=maxb,mid;
while (l<=r)
{
mid= (l+r)/2;
K=pow (mid,n);
if (Fabs (k-p) <ep)
return mid;
if (k<p)
l=mid+1;
else
r=mid-1;
}
return 0;
}
int main ()
{
Ios::sync_with_stdio (false);
while (cin>>n>>p)
{
ll ans=bin_search ();
cout<<ans<<endl;
}
return 0;
}
Answer:
The value of the K can be enumerated in two minutes. Just start looking at the data is very big, come up with high-precision template. The result is a variety of WA, because the high precision is not rounded. Later read Uvatoolkit said directly can use the POW function-_-!!! Then look at the next double representation range, and then use double instead of high precision.
It would be too boring to do this with POW (p,1/n).