Power of Cryptography (binary +POW) __ data structure

Source: Internet
Author: User
Tags pow
D-power of cryptography Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64D &%i64u Submit Status Practice POJ 2109 appoint Description:system Crawler (2015-09-25)

Description current work at cryptography involves (among other things) large prime numbers and computing powers of numbers Among these primes. Work in the has resulted in the practical use of results from number theory and other branches of mathematics once C Onsidered to is only of the theoretical interest.
This problem involves the efficient computation of an 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'll always be of the form K to the n th. Power, for a integer k (this integer is what your program must find).

Input the input consists of a sequence of the integer pairs N and p with each integer in a line by itself. For all such pairs 1<=n<=, 1<=p<10 and there exists a integer k, 1<=k<=10 9 such that k n = P.

Output 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
3
7 4357186184021382204544

Sample Output

4
3
1234
AC Code:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;
#define T 1005
double n,m;
int BS (int l,int R)
{
	int mid;
	while (r>l)
	{
		mid = (l+r) >>1;
		if (POW (double) mid,n) ==m) {return
			mid;
		}
		if (POW (double) mid,n) >m)
			R = mid;
		else
			L = mid+1;
	}
	return 0;
}
int main ()
{
	/*freopen ("Input.txt", "R", stdin); */
	int i,j,k;
	while (~SCANF ("%lf%lf", &n,&m))
	{
		printf ("%d\n", BS (1,1000000000));
	}
	return 0;
}


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.