UVA 113 Power of Cryptography 解题报告
2013-09-03 23:38
501 查看
Power of Cryptography |
Background
Current work in cryptography involves (among other things) large prime numbers and computing powers of numbers modulo functions of these primes. Work in this area has resulted in the practical use of results fromnumber theory and other branches of mathematics once considered to be of only theoretical interest.
This problem involves the efficient computation of integer roots of numbers.
The Problem
Given an integer![](http://uva.onlinejudge.org/external/1/113img1.gif)
and an integer
![](http://uva.onlinejudge.org/external/1/113img2.gif)
you
are to write a program that determines
![](http://uva.onlinejudge.org/external/1/113img3.gif)
, the positive
![](http://uva.onlinejudge.org/external/1/113img4.gif)
root
of p. In this problem, given such integers n and p, p will always be of the form
![](http://uva.onlinejudge.org/external/1/113img5.gif)
for an integerk (this
integer is what your program must find).
The 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![](http://uva.onlinejudge.org/external/1/113img6.gif)
,
![](http://uva.onlinejudge.org/external/1/113img7.gif)
and
there exists an integer k,
![](http://uva.onlinejudge.org/external/1/113img8.gif)
such that
![](http://uva.onlinejudge.org/external/1/113img9.gif)
.
The Output
For each integer pair n and p the value![](http://uva.onlinejudge.org/external/1/113img3.gif)
should be printed, i.e.,
the number k such that
![](http://uva.onlinejudge.org/external/1/113img9.gif)
.
Sample Input
2 16 3 27 7 4357186184021382204544
Sample Output
4 3 1234
此题如果不看大牛的解题报告,而单纯的用大数来做,着实要花费很长的一段时间,而且算法效率无法得到保证。
引用Microsoft技术资源库对于double数据类型的描述:
Double 变量以带符号的 IEEE 64 位(8 个字节)双精度浮点数形式存储,负值取值范围为-1.79769313486231570E+308 到 -4.94065645841246544E-324,正值取值范围为 4.94065645841246544E-324 到 1.79769313486231570E+308。
注意 Double 数据类型可以转换为 Decimal 数据类型,而不会出现 System.OverflowException 错误。
在文本后追加文本类型字符 R 可将其强制转换成 Double 数据类型。在任何标识符后追加标识符类型字符 # 可将其强制转换成 Double 数据类型。
等价的 .NET 数据类型是 System.Double。
在此题中,p的范围并没有超过double数据类型所能表示的整数范围,因而直接使用double类型存储n和p是可行的,代码如下:
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
double n, p;
while(scanf("%lf%lf", &n, &p) != EOF)
printf("%.lf\n", pow(p, 1.0/n));
return 0;
}
相关文章推荐
- UVa 113 Power of Cryptography
- UVa-113-Power of Cryptography
- uva 113 power of Cryptography
- uva 113 - Power of Cryptography
- UVA - 113 Power of Cryptography
- UVa-113-Power of Cryptography
- UVA - 113 Power of Cryptography (大数幂+二分)
- UVA 113 - Power of Cryptography(二分)
- uva 113 Power of Cryptography(开方)
- Uva 113 Power of Cryptography
- UVA 113 Power of Cryptography
- UVA 113 Power of Cryptography
- UVa 113 Power of Cryptography
- UVa OJ 113-Power of Cryptography
- UVa 113 Power of Cryptography
- UVA - 113 - Power of Cryptography
- Uva 113 - Power of Cryptography
- UVa 113 - Power of Cryptography
- POJ2109 ZOJ2486 UVA113 UVALive3098 Power of Cryptography【数学】
- UVA - 113 Power of Cryptography