首页 > 其他分享 >UVa 113 / POJ 2109 Power of Cryptography (使用double处理大整数&泰勒公式与误差分析)

UVa 113 / POJ 2109 Power of Cryptography (使用double处理大整数&泰勒公式与误差分析)

时间:2023-04-12 11:40:40浏览次数:56  
标签:误差 Cryptography Power double 113 onlinejudge problem include


113 - 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


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


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

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

误差分析:

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

则由泰勒公式得

UVa 113 / POJ 2109 Power of Cryptography (使用double处理大整数&泰勒公式与误差分析)_acm

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

 )

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

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

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


完整代码:


/*UVa: 0.015s*/
/*POJ: 0ms,448KB*/

#include <cstdio>
#include <cmath>

int main()
{
	double n, p;
	while (~scanf("%lf%lf", &n, &p))
		printf("%.0f\n", pow(p, 1 / n));
	return 0;
}


Source


México and Central America 2004

标签:误差,Cryptography,Power,double,113,onlinejudge,problem,include
From: https://blog.51cto.com/u_5535544/6185320

相关文章

  • Linux VS Powershell by ChatGPT
    CommandLinuxExamplePowerShellExampledstatdstat-taGet-Counter'\Processor(_Total)%ProcessorTime'sarsar-u110Get-Counter'\Processor(_Total)%ProcessorTime'slurmsbatchscript.shStart-Processpowershell.exe-A......
  • Power BI里面常见的图标
      数值列:列值是数字    日期列:列值是日期 计算列(数字):添加的计算列,列值是数字   计算列(非数字):添加的计算列,列值不是数字    字段的层次结构:比如日期字段,就可以分成年、季度、月、日展示 文件夹:字段的分组,可以将一个/多个列或者度量......
  • power apps canvas 最新scan 扫描功能 barcode, QR code
    Barcodereader现在全面代替barcode scanner barcodereader现在只能通过powerappsmobileapp或者powerappsWindowsUWPapp来使用。还不能通过浏览器使用      Barcodereader控件支持下面数据类型   barcodereader控件和scanner最大的区......
  • Perfect P-th Powers UVA - 10622
     给出n,写成n=x^p的形式,求p最大值#include<iostream>#include<vector>#include<cmath>#include<algorithm>usingnamespacestd;#defineintlonglongintflg=0;intgcd(intx,inty){ returny==0?x:gcd(y,x%y);}voidsov(in......
  • Power Apps Canvas Modern Controls
    Canvas的“丑”一直被人诟病,但是新的moderncontrol基于fluentUI给大家一种回到现代的感觉。https://powerapps.microsoft.com/en-us/blog/modern-controls-coming-to-canvas-apps/新的moderncontrols有这么一些好处现代–一种专注且简洁的设计,支持更丰富的交互状态和层......
  • powershell-json文件解析
    .psobject.properties.name可以获取当前节点下的name(***)而.***获取该name冒号后的内容$path="C:\Users\2\Desktop\R360_TCM_Report_Annie\Local\AnnieCaseReport.json"#$path="C:\Users\2\Desktop\DDDDD\De1.json"$content=(Get-Content$path-Encod......
  • PowerManagerService
    1.唤醒盒子  使盒子进入假待机PowerManagerpowerManager=(PowerManager)getContext().getSystemService(Context.POWER_SERVICE);if(mode.equals("0")){powerManager.goToSleep(SystemClock.uptimeMillis());进入假待机}elseif(mo......
  • 整理房号(Power Query)
    问题:let源=Excel.CurrentWorkbook(){[Name="表1"]}[Content],替换租户=Table.ReplaceValue(源,"租户","",Replacer.ReplaceText,{"房号"}),替换二次装修=Table.ReplaceValue(替换租户,"(二次装修)","",Replacer.Rep......
  • 不需要第一行的多表合并(Power Query)
    问题:多工作表合并,但第一行不需要,标题行从第二行起。let源=Excel.Workbook(File.Contents("路径\文件名.xlsx")),规范表=Table.TransformColumns(源,{"Data",eachTable.PromoteHeaders(Table.Skip(_,1))}),删除列=Table.SelectColumns(规范表,{"Data"}),......
  • 多条数据并成一条后合并查询(Power Query)
    问题:两表合并,其中一表有重复的数据需要事先求和或合并let源=Excel.CurrentWorkbook(){[Name="表1"]}[Content],合并查询=Table.NestedJoin(源,{"订单号"},表2,{"订单号"},"表2",JoinKind.LeftOuter),展开=Table.ExpandTableColumn(合并查询,"表2......