Poj 2109/openjudge 2109 power of cryptography

Source: Internet
Author: User

1. Link:

Http://poj.org/problem? Id = 2109

Http://bailian.openjudge.cn/practice/2109/

2. content:

Power of cryptography
Time limit:1000 ms   Memory limit:30000 K
Total submissions:18872   Accepted:9520

Description

Current work in cryptography involves (among other things) large prime numbers and computing powers of numbers among 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 only of theoretical interest.
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 nth. power, for an integer k (this integer is what your program must find ).

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 <10101 and there exists an integer k, 1 <= k <= 109 such that kN = P.

Output

For each integer pair N and P the value K shoshould be 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

3. Method:

Derivation process:

K ^ n = P

Logk P = N

Log (P)/log (K) = N (bottom-changing formula)

Log (K) = 1/N * log (P)

K = e ^ (1/n * log (p) = (E ^ log (p) ^ (1/n) = P ^ (1/n) = POW (P, 1/n)

Therefore, using double to read data will result in loss of some precision, but this question seems to be less accurate, so it is feasible

4. Code:

 1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4  5 using namespace std; 6  7 int main() 8 { 9     //freopen("D://input.txt","r",stdin);10     11     double p,n;12     13     while(cin >> n >> p)14     {15         cout << pow(p,1.0/n) << endl;16     }17     18     return 0;19 }

 

5. Reference:

Poj 2109/openjudge 2109 power of cryptography

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.