您的位置:首页 > 其它

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 from
number 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

and an integer

you
are to write a program that determines

, the positive

root
of p. In this problem, given such integers n and p, p will always be of the form

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

,

and
there exists an integer k,

such that

.

The Output

For each integer pair n and p the value

should be printed, i.e.,
the number k such that

.

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;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: