Power of Cryptography
Time Limit: 1000 MS Memory Limit: 30000 K
Total Submissions: 16238 Accepted: 8195
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 16
3 27
7 4357186184021382204544 Sample Output
4
3
1234 Source
México and Central America 2004
Question: calculate k to make k ^ n = p for a pair of numbers n (1 <= n <= 200) and p (1 <= p <= 10 ^ 101.
Analysis: 1. It is natural to think that the data is big and high precision is required. Then, add a binary number.
It won't be accurate ..
2. Think of conversion mathematical operations: peer-to-peer. It is saved as double, but the exact bit of double is only 6-7. Without logx Y, only the base-e logarithm is first converted. Use lognP = logn/logP. Using two functions,
Precision cannot meet requirements.
3. Another idea: k ^ n = p, then p ^ (1/n) = k. And the function can use pow (x, y) to calculate x ^ y directly.
Gains: consolidate the foundation. Inspired by thinking.
Valid numeric absolute value range of Type length (bit)
Float 32 6 ~ 7 10 ^ (-37 )~ 10 ^ 38
Double 64 15 ~ 16 10 ^ (-307 )~ 10 ^ 308
Long double 128 18 ~ 19 10 ^ (-4931 )~ 10 ^ 4932
Code:
#include<cstdio>#include<iostream>#include<cmath>using namespace std;int main(){ double n,p; while(scanf("%lf%lf",&n,&p)!=EOF) { printf("%.0lf\n",pow(p,1/n)); } return 0;}