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 4357186184021382204544

Sample Output

4
3
1234

Source

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的更多相关文章

  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 Power of Cryptography

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

  3. POJ 2109 :Power of Cryptography

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

  4. POJ 2109 -- Power of Cryptography

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

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

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

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

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

  7. [POJ2109]Power of Cryptography

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

  8. UVA 113 Power of Cryptography (数学)

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

  9. POJ2109——Power of Cryptography

    Power of Cryptography DescriptionCurrent work in cryptography involves (among other things) large pr ...

随机推荐

  1. w3cmark前端精彩博文周报 10.27-11.2

    w3cmark 官方Q群 145423956 | 官方微博 @w3cmark 这周周报来迟了,公司真的好忙!!!欢迎关注我们的微博 @w3cmark w3cmark推出每周精选前端博文推荐,通过阅读别 ...

  2. 【智能家居篇】wifi在智能家居中的应用

    转载请注明出处:http://blog.csdn.net/Righthek 谢谢! 在设计智能家居系统方案时,一个很关键的point就是组网方式.组网方式关系到整个智能家居系统的稳定性.可扩展性.实时 ...

  3. 比较escape、encodeURI、encodeURIComponent

    估计很多前端工程师并不清楚escape,encodeURI, encodeURIComponent的区别,也不知道什么时候该用哪个方法,以及这些方法为什么要被用到,下面我主要来阐述一下这三个方法的区别 ...

  4. Linux内核初始化定义

    转载:http://blog.csdn.net/beatbean/article/details/8448623 1. Compile宏控制 位于include/linux/init.h /* The ...

  5. Spring3之Security

    1.spring security介绍 Spring Security原来叫做Acegi Security,可用于加强任何Java应用的安全,但是最常用于基于Web的应用.下面首先理解几个安全术语: ...

  6. PHP读书笔记(7)- 函数

    自定义函数 PHP内置了超过1000个函数,因此函数使得PHP成为一门非常强大的语言.大多数时候我们使用系统的内置函数就可以满足需求,但是自定义函数通过将一组代码封装起来,使代码进行复用,程序结构与逻 ...

  7. 第一节:Maven 下载,安装和配置

    Maven是Apache的一个产品所以要下载Maven的话可以到https://www.apache.org网站上下载 进入到APache这个网站后看一下几部操作 第一: 选择点击导航栏上面的proj ...

  8. [转]DataTable用中使用Compute 实现简单的DataTable数据的统计

    本文转自:http://blog.csdn.net/zwxrain/article/details/252285 調用格式: object DataTable.Compute(string expre ...

  9. [改善Java代码]使用forName动态加载类文件

    动态加载(Dynamic Loading)是指在程序运行时加载需要的类库文件,对Java程序来说,一般情况下,一个类文件在启动时或首次初始化时会被加载到内存中,而反射则可以在运行时再决定是否需要加载一 ...

  10. [改善Java代码]避免对象的浅拷贝

    建议43: 避免对象的浅拷贝 我们知道一个类实现了Cloneable接口就表示它具备了被拷贝的能力,如果再覆写clone()方法就会完全具备拷贝能力.拷贝是在内存中进行的,所以在性能方面比直接通过ne ...