Time Limit: 3.000 seconds
Time Limit: 3.000 seconds
Background
Background
Current work in cryptography involves (among other things) large prime numbers and computing powers of numbers modulo functions of these primes. work in this area has resulted in the practical use of results from number theory and other branches of mathematics once considered to be of only theoretical interest.
This problem involves the efficient computation of integer roots of numbers.
The Problem
Problem
Given an integer n ≥ 1 and an integer p ≥ 1 you are to write a program that determines, the positive nth root of P. in this problem, given such integers N and P, P will always be of the form kN for an integer k (this integer is what your program must find ).
The input
Input
The input consists of a sequence of integer pairs N and P with each integer on a line by itself. for all such pairs 1 ≤ n ≤ 200, 1 ≤ p ≤ 10101and there exists an integer k, 1 ≤ k ≤ 109 such that kN = P.
The output
Output
For each integer pair N and P the value shoshould be printed, I. e., the number k such that kN = P.
Sample Input
2
16
3
27
7
4357186184021382204544
Sample output
4
3
1234
Analysis
I was shocked when I got the answer to this question. Is it true that I can implement a large number of values?Algorithm? I first thought of the big Integer Operation, and then thought of the Newton Iteration Method. Finally, we found that the given P value does not exceed the range expressed by double ...... Let's not talk about anything.CodeRight.
Solution
# Include <iostream> # include <math. h> using namespace STD; int main (void) {for (double dnum, dpow; CIN> dpow> dnum; cout <(INT) (POW (dnum, 1.0/dpow) + 0.5) <Endl); Return 0 ;}