Power of Cryptography

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem&problem=49

http://poj.org/problem?id=2109

 
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 19772   Accepted: 9984

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

题意:给出n和p,求出 ,但是p可以很大(

如何存储p?不用大数可不可以?

先看看double行不行:指数范围在-307~308之间(以10为基数),有效数字为15位。

误差分析:

令f(p)=p^(1/n),Δ=f(p+Δp)-f(p)

则由泰勒公式得

(Δp的上界是因为double的精度最多是15位,n有下界是因为 )

由上式知,当Δp最大,n最小的时候误差最大。

根据题目中的范围,带入误差公式得Δ<9.0e-7,说明double完全够用(这从一方面说明有效数字15位还是比较足的(相对于float))

这样就满足题目要求,所以可以用double过这一题。

 #include<stdio.h>
#include<math.h>
using namespace std;
double n;
double p ; int main ()
{
// freopen ("a.txt" , "r" , stdin);
while (~ scanf ("%lf%lf" , &n , &p)) {
printf ("%.0f\n" , pow (p , 1.0 / n)) ;
}
return ;
}

转载:http://blog.csdn.net/synapse7/article/details/11672691

Power of Cryptography(用double的泰勒公式可行分析)的更多相关文章

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

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

  2. 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 ...

  3. [POJ2109]Power of Cryptography

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

  4. 贪心 POJ 2109 Power of Cryptography

    题目地址:http://poj.org/problem?id=2109 /* 题意:k ^ n = p,求k 1. double + pow:因为double装得下p,k = pow (p, 1 / ...

  5. poj 2109 Power of Cryptography

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

  6. UVA 113 Power of Cryptography (数学)

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

  7. POJ2109——Power of Cryptography

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

  8. POJ 2109 :Power of Cryptography

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

  9. POJ 2109 -- Power of Cryptography

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

随机推荐

  1. Chrome扩展开发之四——核心功能的实现思路

    目录: 0.Chrome扩展开发(Gmail附件管理助手)系列之〇——概述 1.Chrome扩展开发之一——Chrome扩展的文件结构 2.Chrome扩展开发之二——Chrome扩展中脚本的运行机制 ...

  2. Pivot的SelectionChanged事件绑定到VM的Command

    我要实现的是页面加载时,只获取SelectedIndex=0的数据,然后根据Pivot的SelectionChanged动态获取其他项的数据,我用的是MVVM的Command的方式,不想用后台注册事件 ...

  3. How to set China Azure Storage Connection String

    Configure Visual Studio to access China Azure Storage Open Visual Studio 2012, Server Explorer Add n ...

  4. (好文推荐)一篇文章看懂JavaScript作用域链

    闭包和作用域链是JavaScript中比较重要的概念,首先,看看几段简单的代码. 代码1: var name = "stephenchan"; var age = 23; func ...

  5. WCF安装Windows服务

    安装图解: 安装命令: 1. 开始 ->运行 ->cmd2. cd到C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319(Framework版本号按I ...

  6. Kettle_使用Pan.bat执行转换、Kitchen.bat执行作业

    参考资料:http://www.cnblogs.com/wxjnew/p/3620792.html 注意:使用bat文件执行速度比执行在spoon.bat中执行慢很多 一.使用Pan.bat执行转换 ...

  7. 基本的mediaQuery写法,不复习又忘记了

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  8. Cocos2d-X3.0 刨根问底(八)----- 场景(Scene)、层(Layer)相关源码分析

    本章节我们重点分析Cocos2d-x3.0与 场景.层相关的源码.这部分源码集中在 libcocos2d –> layers_scenes_transitions_nodes目录下面 我先发个截 ...

  9. BZOJ-1491 社交网络 FLoyd+乱搞

    感觉这两天一直在做乱搞的题... 1491: [NOI2007]社交网络 Time Limit: 10 Sec Memory Limit: 64 MB Submit: 1279 Solved: 732 ...

  10. 【poj1745】 Divisibility

    http://poj.org/problem?id=1745 (题目链接) 题意 给出n串数,可以在其两两之间添加+或-,判断是否存在某种方案使得出的表达式的答案可以整除k. Solution 水题一 ...