D-power of cryptography
Time Limit:1000MS
Memory Limit:30000KB
64bit IO Format:%I64D &%i64u Submit Status Practice POJ 2109 appoint Description:system Crawler (2015-09-25)
Description current work at cryptography involves (among other things) large prime numbers and computing powers of numbers Among these primes. Work in the has resulted in the practical use of results from number theory and other branches of mathematics once C Onsidered to is only of the theoretical interest.
This problem involves the efficient computation of an 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'll always be of the form K to the n th. Power, for a integer k (this integer is what your program must find).
Input the input consists of a sequence of the integer pairs N and p with each integer in a line by itself. For all such pairs 1<=n<=, 1<=p<10 and there exists a integer k, 1<=k<=10 9 such that k n = P.
Output for each integer pair n and p the value K should is printed, i.e., the number k such that K n =p.
Sample Input
2
3
7 4357186184021382204544
Sample Output
4
3
1234
AC Code:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;
#define T 1005
double n,m;
int BS (int l,int R)
{
int mid;
while (r>l)
{
mid = (l+r) >>1;
if (POW (double) mid,n) ==m) {return
mid;
}
if (POW (double) mid,n) >m)
R = mid;
else
L = mid+1;
}
return 0;
}
int main ()
{
/*freopen ("Input.txt", "R", stdin); */
int i,j,k;
while (~SCANF ("%lf%lf", &n,&m))
{
printf ("%d\n", BS (1,1000000000));
}
return 0;
}