Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 20351   Accepted: 10284

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 should 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
注:这题分类是贪心算法,但是看了discuss之后竟然发现用double一句可以AC,也是醉了
k^n=p
n=log(p)/log(k)
log(k)=log(p)/n
2^log(k)=2^(log(p)/n)
k=p^(1/n)
附:float,double,long double的范围
类型          长度 (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
 #include<iostream>
#include<math.h>
using namespace std; int main()
{
double n,p;
while(cin>>n>>p)
cout<<pow(p,1.0/n)<<endl;
return ;
}

Power of Cryptography - poj 2109的更多相关文章

  1. 贪心 POJ 2109 Power of Cryptography

    题目地址:http://poj.org/problem?id=2109 /* 题意:k ^ n = p,求k 1. double + pow:因为double装得下p,k = pow (p, 1 / ...

  2. Poj 2109 / OpenJudge 2109 Power of Cryptography

    1.Link: http://poj.org/problem?id=2109 http://bailian.openjudge.cn/practice/2109/ 2.Content: Power o ...

  3. poj 2109 Power of Cryptography

    点击打开链接 Power of Cryptography Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 16388   Ac ...

  4. POJ 2109 :Power of Cryptography

    Power of Cryptography Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 18258   Accepted: ...

  5. POJ 2109 -- Power of Cryptography

    Power of Cryptography Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 26622   Accepted: ...

  6. POJ 2109 Power of Cryptography 数学题 double和float精度和范围

    Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 21354 Accepted: 107 ...

  7. Power of Cryptography(用double的泰勒公式可行分析)

    Power of Cryptography Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onli ...

  8. [POJ2109]Power of Cryptography

    [POJ2109]Power of Cryptography 试题描述 Current work in cryptography involves (among other things) large ...

  9. UVA 113 Power of Cryptography (数学)

    Power of Cryptography  Background Current work in cryptography involves (among other things) large p ...

随机推荐

  1. [BZOJ4398]福慧双修/[BZOJ2407]探险

    题目大意: 给定一个$n(n\leq40000)$个点$m(m\leq100000)$条边的有向图,求从$1$出发回到$1$的不经过重复结点的最短路. 思路: 首先Dijkstra求出从1出发到每个结 ...

  2. sed 中如何替换换行符

    使用如下解决方案: sed ':a;N;$!ba;s/\n/ /g' 这将在一个循环里读取整个文件,然后将换行符替换成一个空格. 说明: 通过 :a创建一个标记 通过N追加当前行和下一行到模式区域 如 ...

  3. SQL SERVER Update from 使用陷阱

    原文:SQL SERVER Update from 使用陷阱 update A set from A left join B on 此方法常用来使用根据一个表更新另一个表的数据,来进行数据同步更新.若 ...

  4. iptables 要点总结

    http://jiayu0x.com/2014/12/02/iptables-essential-summary/

  5. c++中resize这个函数怎么用

    c++中序列式容器的一个共性函数, vv.resize(int n,element)表示调整容器vv的大小为n,扩容后的每个元素的值为element,默认为0 resize()会改变容器的容量和当前元 ...

  6. 咏南下拉列表数据敏感控件--TYNDBSearch

    咏南下拉列表数据敏感控件--TYNDBSearch 拥有下拉列表控件可以大大地加速软件系统的开发. 控件适用于DELPHI5及以上版本安装并使用. 控件的用法: procedure Tfgoods.s ...

  7. shoppingCart.js

    ylbtech-JavaScript-util: shoppingCart.js 购物车脚本 1.A,JS-效果图返回顶部   1.B,JS-Source Code(源代码)返回顶部 1.B.1,m. ...

  8. 安装docker-compose的两种方式

    这里简单介绍下两种安装docker-compose的方式,第一种方式相对简单,但是由于网络问题,常常安装不上,并且经常会断开,第二种方式略微麻烦,但是安装过程比较稳定 方法一: # curl -L h ...

  9. linux系统清理僵尸进程记录

    在UNIX 系统中,一个进程结束了,但是他的父进程没有等待(调用wait / waitpid)他, 那么他将变成一个僵尸进程.  在fork()/execve()过程中,假设子进程结束时父进程仍存在, ...

  10. Hibernate分页功能数据重复问题

    今天遇到一个很憋屈的问题那就是hibernate分页查询中出现重复数据,本来一直没有在意,以为是数据问题,但是一查程序和数据都没有问题,继续深入查看,找到问题了就是order By 时出的问题,唉.. ...