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. 通过爬虫代理IP快速增加博客阅读量——亲测CSDN有效!

    写在前面 题目所说的并不是目的,主要是为了更详细的了解网站的反爬机制,如果真的想要提高博客的阅读量,优质的内容必不可少. 了解网站的反爬机制 一般网站从以下几个方面反爬虫: 1. 通过Headers反 ...

  2. WINDOWS下用脚本运行redis和mongodb

    开发环境每次开麻烦,又不想建service,用bat最简单 @echo off echo 打开NOSLQ服务 start E:\nosql\mongodb\mongod.exe -dbpath e:\ ...

  3. Library not found for -lPods 解决方法

    使用cocoapods 经常会遇到的问题. 1. Library not found for -lPods 2. Pods was rejected as an implicit dependency ...

  4. 年前辞职-WCF入门(6)

    前言 昨天早上去医院做入职体检,被告知要预约,本以为是要排队,我连视频都准备好了...结果就回来了.下午去了新公司那边找房子,2了,因为公司提供了班车列表,我既然就只在班车所经过的几个地方找,却遗漏了 ...

  5. 复合sql

    update select update bucp..Core_Flow_Opinion set useruid =(select user_uid from bua..bua_user b wher ...

  6. Linux(CentOS)下安装git

    上个月把VPS迁到budgetVM,终于不用再受digitalOcean的气了,入手很方便,重点是支持支付宝付款——paypal的界面真是不习惯,开通速度挺快的,1G的内存够我折腾一段时间了~,额外送 ...

  7. tarjan算法--求无向图的割点和桥

    一.基本概念 1.桥:是存在于无向图中的这样的一条边,如果去掉这一条边,那么整张无向图会分为两部分,这样的一条边称为桥无向连通图中,如果删除某边后,图变成不连通,则称该边为桥. 2.割点:无向连通图中 ...

  8. 【HDU 1228】A + B

    题 Description 读入两个小于100的正整数A和B,计算A+B. 需要注意的是:A和B的每一位数字由对应的英文单词给出.    Input 测试输入包含若干测试用例,每个测试用例占一行,格式 ...

  9. 判断一个数据是否存在于一个表中,Oracle中写自定义函数

    create or replace function isExist(data in DataTypes) --DataTypes 为表中该数据的类型return Numberisv_flag num ...

  10. MySQL tips (日期时间操作/concat 等)

    1.  Query结尾要加一个分号: 2.  数据库和表 SHOW DATABASES;    USE YOUR_DB; SHOW TABLES; SHOW COLUMNS FROM study或者D ...