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. android的adb详解(多设备时adb调用)

    在多设备(模拟器)时,想要直接用logcat查看其中一台的状态,或者直接把应用安装到目标设备上时,需要指定设备号.adb devices这个指令可以得到当前设备的序列号(serialNumber).比 ...

  2. 如何构建JSON数据,JSON数据的格式,JSON数据的获取

    假设你是用$.getJSON();方法获取JSON数据$.getJSON(url,{"Action":"getStudent"},function(data){ ...

  3. 高校手机签到系统——zxing.net生成二维码(补充)

    高校手机签到系统——第一部分Authority权限系统(上) 高校手机签到系统——第一部分Authority权限系统(下) 高校手机签到系统——手机客户端 关于zxing.net的使用网上已有很多说明 ...

  4. asp.net Core开启全新的时代,用视频来告诉你,学习就是这么SO easy。

    https://channel9.msdn.com/Blogs/NET-Core/What-is-NET-Core 系统大家多发布一些视频的资料,学习起来更方便!我看到很多人发布的博客里面有的时候对于 ...

  5. C# ArcEngine创建内存图层(转载)

    C#+Arcengine---创建内存图层 分类:技术文档 2009-12-11 14:43阅读(1498)评论(0) #region 在内存中创建图层        /// <summary& ...

  6. [设计模式] javascript 之 抽象工厂模式

    抽象工厂模式说明 1. 工厂方法模式的问题: 在工厂方法模式里,创建类都需要通过 工厂类,如果要扩展程序,就必须修改工厂类,这违背了闭包原则,对扩展开放,对修改关闭:对于设计有一定的问题. 2. 如何 ...

  7. jQuery基础之(五)jQuery自定义添加"$"与解决"$"的冲突

    1.自定义添加$ 从上面四篇文章我们看到jQuery的强大,但无论如何,jQuery都不可能满足所有用户的需求,而且有一些需求十分小众,也不适合放到整个jQuery框架中,正是因为这一点,jQuery ...

  8. 序列化类型为“System.Data.Entity.DynamicProxies.ActionInfo_”的对象时检测到循环引用。

    解决方案: 加上 db.Configuration.ProxyCreationEnabled = false;这句话搞定~

  9. php Curl_setop 的学习

    cur_op的学习 ###curl_setopt (int ch, string option, mixed value) option的参数 CURLOPT_INFILESIZE: 当你上传一个文件 ...

  10. win8 配 jdk

    Win8配置jdk 1.7环境变量  环境:win8(32位)64位差不多       jdk1.7    1.右击计算机-属性-高级系统设置-高级-环境变量,弹出“环境变量”对话框,主要是改下面的环 ...