Power of cryptography

Source: Internet
Author: User

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

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.