Description
Cryptography involves (among other things) large prime numbers and computing powers of numbers among these Primes. resulted in the practical use of results from number theory and other branches of mathematics once C Onsidered to is only of theoretical interest.
This problem involves the efficient computation of the 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 is always being of the form K to the nth. Power, for a integer k (this is the what your program must find).
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<=, 1<=p<10101 and there exists a integer k, 1<=k<=109 such that kn = P.
Output
The 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 163 277 4357186184021382204544
Sample Output
431234
Source
México and Central America 2004 the main idea: the use of dichotomy (LOG2N) does not time out
#include <cstdio>#include<math.h>intMain () {Doublep,n,k; Long Long intEnd,mid,begin; while(~SCANF ("%LF%LF",&n,&p)) {End=1000000000, begin =1; while(Begin <=end) {Mid= (begin + END)/2 ; K=Pow (mid,n); if(k<Q) {Begin=mid; } Else if(k>p) {End=Mid;} Else{printf ("%lld\n", mid); Break; } } } return 0;}
View Code
Power of cryptography