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 ...
随机推荐
- Telnet、SSH和VNC
以下内容出自<Red Hat Linux服务器配置与应用>第17章:Telnet.SSH和VNC服务的配置与应用.俗话说:“前人栽树,后人乘凉”.我懒得再照书本打一遍了,就从这里拷贝了一份 ...
- 【不怕坑】之 Node.js加密 C#解密
本人也不太了解AES加密解密,为了解决Node.js加密,但是无法C#解密的问题,在网上搜了大量的相关文章. 但是多数是Node.js vs Java 或 Java vs C#的双向加密解密代码,但是 ...
- eclipse 的小技巧
1. ctrl+o:快速outline 如果想要查看当前类的方法或某个特定方法,但又不想把代码拉上拉下,也不想使用查找功能的话,就用ctrl+o吧.它可以列出当前类中的所有方法及属性,你只需输入你想要 ...
- css笔记05:表单
1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.o ...
- 为Mono安装MySql连接驱动
为Mono安装MySql连接驱动(转) 2013 年 1 月 24 日.NETmono.MySql DOTNET and Mono by default only support database c ...
- Hummer框架平台介绍
三年工作过程中经常会用到使用Java开源框架,但经常会遇到重新组合比较麻烦,本次采用目前主流开源框架及插件整理出一套融合开发.测试.部署整个流程的平台. 本平台采用Hummer代号,是悍马和蜂鸟分意思 ...
- SQL Server 通配符 Wildcard character
SQL Server 通配符 Wildcard character % 任意长度的字符串,如:'%computer%' _ 单个字符,如:'_ean' [] ...
- 最简单的Linux-ACL操作
添加ACL setfacl -m u:'username':rw 'dir or file' "-R可以迭代式的给目录下所有文件都添加相同的ACL" 查看ACL规则 getfa ...
- 关于cmd模式下切换目录
cmd下切换目录: 经常犯下的错误一: 在默认路径下输入 cd D: 想切换到D盘但是会出现上面的现象. 正确的的做法是直接输入要转移到的盘符: D: 就可以了. 在这种情况下再输入cd D:
- Wince 对话框程序设计
如何编程实现wince下“打开文件夹对话框”呢?这里就要涉及到下面要分析的知识了,对话框是一种特殊的窗口,它在wince 作为应用程序和程序使用者之间的交流窗口,通过显示和获取信息使人们的交流更加方便 ...