Poj 2109 / OpenJudge 2109 Power of Cryptography
1.Link:
http://poj.org/problem?id=2109
http://bailian.openjudge.cn/practice/2109/
2.Content:
Power of Cryptography
Time Limit: 1000MS Memory Limit: 30000K 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 should be printed, i.e., the number k such that k n =p.Sample Input
2 16
3 27
7 4357186184021382204544Sample Output
4
3
1234Source
3.Method:
推导过程:
K^N = P
logk P = N
log(P) / log(k) = N (换底公式)
log(K) = 1/N * log(P)
K = e ^ ( 1/N * log(P)) = ( e ^ log(P)) ^ (1/N) = P ^ (1/N) = pow(P,1/N)
因此采用double读入,会损失部分精度,但是这题貌似精度没有那么高,所以可行
4.Code:
#include <iostream>
#include <cstdio>
#include <cmath> using namespace std; int main()
{
//freopen("D://input.txt","r",stdin); double p,n; while(cin >> n >> p)
{
cout << pow(p,1.0/n) << endl;
} return ;
}
5.Reference:
Poj 2109 / OpenJudge 2109 Power of Cryptography的更多相关文章
- 贪心 POJ 2109 Power of Cryptography
题目地址:http://poj.org/problem?id=2109 /* 题意:k ^ n = p,求k 1. double + pow:因为double装得下p,k = pow (p, 1 / ...
- poj 2109 Power of Cryptography
点击打开链接 Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16388 Ac ...
- POJ 2109 :Power of Cryptography
Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 18258 Accepted: ...
- POJ 2109 -- Power of Cryptography
Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 26622 Accepted: ...
- POJ 2109 Power of Cryptography 数学题 double和float精度和范围
Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 21354 Accepted: 107 ...
- Power of Cryptography(用double的泰勒公式可行分析)
Power of Cryptography Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onli ...
- [POJ2109]Power of Cryptography
[POJ2109]Power of Cryptography 试题描述 Current work in cryptography involves (among other things) large ...
- UVA 113 Power of Cryptography (数学)
Power of Cryptography Background Current work in cryptography involves (among other things) large p ...
- POJ2109——Power of Cryptography
Power of Cryptography DescriptionCurrent work in cryptography involves (among other things) large pr ...
随机推荐
- MaterialDesignLibrary
https://github.com/navasmdc/MaterialDesignLibrary MaterialDesignLibrary.zip
- android圆角View实现及不同版本这间的兼容(android3.0过后的版本)
http://blog.csdn.net/lovecluo/article/details/8710174 在做我们自己的APP的时候,为了让APP看起来更加的好看,我们就需要将我们的自己的View做 ...
- [AngularJS] $http cache
By default your HTTP requests with the $https service in Angular are not cached. By setting some opt ...
- iOS开发——网络编程Swift篇&(八)SwiftyJSON详解
SwiftyJSON详解 最近看了一些网络请求的例子,发现Swift在解析JSON数据时特别别扭,总是要写一大堆的downcast(as?)和可选(Optional),看?号都看花了.随后发现了这个库 ...
- 解决PowerDesigner 反向工程没有注释(备注)
本文转载自:http://www.cnblogs.com/zhangxb/archive/2012/04/20/2458898.html 1. 列注释 原来代码: {OWNER, TABLE, S, ...
- JavaScript 关于this的理解
this是一个挺神奇的东西,经常不知道它绑定到了那里 ,因此出来了各种绞尽脑汁的面试题. 例1 <script> var person={}; person.name='li'; pers ...
- c# 友元程序集
在团队开发中,如果一个程序集中要调用另外一个程序集,但是要被调用的那个程序集又不想用public来公开自己的类, 那么怎么办,就是用最后一种internal来用来做类的可见性了. 下面来看一个简单例子 ...
- Ventuz配置Leap Motion环境
1.下载Leap Dev Kit 前往官网www.leapmotion.com,下载相应平台的开发包,目前PC版的最新版本为2.3.1. SDK里包含了Leap Motion的安装包,上图第二个.安装 ...
- [改善Java代码]asList方法产生的List对象不可更改
上一个建议之处了asList方法在转换基本类型数组时候存在的问题,在看下asList方法返回的列表有何特殊的地方.看代码: import java.util.Arrays; import java.u ...
- android开发推荐书籍列表
1. <第一行android代码> 入门,简单易懂,全面. 2. << Android群英传 >> 特点:UI部分相当详细 3. <<深入理解Andr ...