UVA 113 Power of Cryptography (数学)
| 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
double能表示的范围是-1.7e308 ~ 1.7e308,精度至少为15位,而输出结果在int的范围内,即10位,所以可以输出可以用double
至于计算过程中为什么能用double而不会影响到结果,我也暂时没搞懂,因为double的精度只有15位,最多也才有16位,但是p的范围是10^101,输入过程中用的也不是科学计数法,15位后的值肯定被抹掉了,结果却是对的。
正确的分析应该在这:http://blog.csdn.net/synapse7/article/details/11672691,用到了误差分析,得出的结果是在这一题里失去的精度不会影响答案,等我数学补上来之后来研究(吐槽一下网上的好多人,风轻云淡的就发上来了,真的懂了么?自己不扎实不要紧,关键在于误导了新手)
#include<stdio.h>
#include<math.h> int main(void)
{
double n,p; while(scanf("%lf%lf",&n,&p) != EOF)
printf("%.lf\n",pow(p, / n)); return ;
}
UVA 113 Power of Cryptography (数学)的更多相关文章
- POJ-2109 Power of Cryptography(数学或二分+高精度)
题目链接: https://vjudge.net/problem/POJ-2109 题目大意: 有指数函数 k^n = p , 其中k.n.p均为整数且 1<=k<=10^9 , 1< ...
- 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 ...
- 贪心 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 / OpenJudge 2109 Power of Cryptography
1.Link: http://poj.org/problem?id=2109 http://bailian.openjudge.cn/practice/2109/ 2.Content: Power o ...
- POJ2109——Power of Cryptography
Power of Cryptography DescriptionCurrent work in cryptography involves (among other things) large pr ...
- uva 10330 - Power Transmission(网络流)
uva 10330 - Power Transmission 题目大意:最大流问题. 解题思路:増广路算法. #include <stdio.h> #include <string. ...
- UVA 11149 - Power of Matrix(矩阵乘法)
UVA 11149 - Power of Matrix 题目链接 题意:给定一个n*n的矩阵A和k,求∑kiAi 思路:利用倍增去搞.∑kiAi=(1+Ak/2)∑k/2iAi,不断二分就可以 代码: ...
随机推荐
- 开源文件比较工具:WinMerge、KDiff3、diffuse
为了寻找免费的BeyondCompare的替代品,最后经过实用,找到如下一些: 1.diffuse 感受:如果仅仅是比较两个文本类的文件,这个软件也就够用了. 安装好后,对着文件点击右键,会出现“Op ...
- Xcode快捷键整理
下面是Xcode比较常用的快捷键,特别是红色标注的,很常用.用熟了开发编辑代码的的时候就很方便,希望对大家有用~1. 文件CMD + N: 新文件CMD + SHIFT + N: 新项目CMD + O ...
- ClassRequestHandler or VendorRequestHandler wIndex must be less than NumIFs
P1_ro:20000EEA ClassRequestHandler ; CODE XREF: USB__HandleSetup+38j P1_ro:20000EEA LDRB R0, [R4,#4] ...
- Cortex-M3 Context Switching
http://www.embedded.com/design/embedded/4231326/Taking-advantage-of-the-Cortex-M3-s-pre-emptive-cont ...
- The source attachment does not contain the source for the file SignatureParser.class错误
在myeclipse整合tomcat的完毕后,再启动tomcat的时候会出现这样的错误,呵呵,错误的大致意思是什么相关联错误,其实是myeclipse新加入的tomcat的模式出现错误了,myecli ...
- Android Studio初步使用教程
今年的Google全球开发者大会虽然没有新的Android系统和设备,但是还是推出了一些不错的产品,Android Studio就是其中之一.这个基于Intellij IDEA开发的Android I ...
- mvc cookie
Response.Cookies["userName"].Value = "ddd"; <% if (Request.Cookies[" ...
- Android C2DM学习 - 云端推送
一.基础知识 当我们开发需要和服务器交互的应用程序时,基本上都需要获取服务器端的数据,比如<地震及时通>就需要及时获取服务器上最新的地震信息.要获取服务器上不定时更新的信息一般来说有两种方 ...
- AJAX responseText vs responseXML
AJAX------>本质 Request/Response(Server)模式 response的形式 responseText--------->获得字符串形式的响应数据. ----- ...
- html+css 知识整理
1.学网页最好的方法:学习别人的网页. 2.文档结构 <html>(超文本标记语言) <head> <title> </title> & ...