Power of Cryptography

Time Limit: 1000MS Memory Limit: 30000K

Total Submissions: 21354 Accepted: 10799

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

Source

México and Central America 2004

看到这么大的数,,首先就想到了高精度,,大数写的欲哭无泪,,看了下题解,,才愕然发现可以直接计算的,,

1.pow(x,y)函数变量是double型

2.float与double的范围和精度



1. 范围

float和double的范围是由指数的位数来决定的。

float的指数位有8位,而double的指数位有11位,分布如下:

float:

1bit(符号位) 8bits(指数位) 23bits(尾数位) !!!!!!!!!!!!!!!!!!!!!!!!!(理解)

double:

1bit(符号位) 11bits(指数位) 52bits(尾数位)

于是,float的指数范围为-127~+128,而double的指数范围为-1023~+1024,并且指数位是按补码的形式来划分的。

其中负指数决定了浮点数所能表达的绝对值最小的非零数;而正指数决定了浮点数所能表达的绝对值最大的数,也即决定了浮点数的取值范围。

float的范围为-2^128 ~ +2^128,也即-3.40E+38 ~ +3.40E+38;double的范围为-2^1024 ~ +2^1024,也即-1.79E+308 ~ +1.79E+308。!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

2. 精度

float和double的精度是由尾数的位数来决定的。浮点数在内存中是按科学计数法来存储的,其整数部分始终是一个隐含着的“1”,由于它是不变的,故不能对精度造成影响。

float:2^23 = 8388608,一共七位,这意味着最多能有7位有效数字,但绝对能保证的为6位,也即float的精度为6~7位有效数字;

double:2^52 = 4503599627370496,一共16位,同理,double的精度为15~16位。

float8个指数位,指数最大时128,所以能存的最大的数是2^128=3*10^38=10^38;

double11个指数位,指数最大时1024,所以能存的最大的数是2^128=3*10^38=1.79*10^308=10^108;

#include <iostream>
#include <cstring>
#include <cstdio>
#include<cmath>
using namespace std;
int main()
{
double n,p;
while(~scanf("%lf %lf",&n,&p))
printf("%.0lf\n",pow(p,1/n));
return 0;
}

POJ 2109 Power of Cryptography 数学题 double和float精度和范围的更多相关文章

  1. 贪心 POJ 2109 Power of Cryptography

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

  2. poj 2109 Power of Cryptography

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

  3. POJ 2109 -- Power of Cryptography

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

  4. poj 2109 Power of Cryptography (double 精度)

    题目:http://poj.org/problem?id=2109 题意:求一个整数k,使得k满足kn=p. 思路:exp()用来计算以e为底的x次方值,即ex值,然后将结果返回.log是自然对数,就 ...

  5. POJ 2109 Power of Cryptography【高精度+二分 Or double水过~~】

    题目链接: http://poj.org/problem?id=2109 参考: http://blog.csdn.net/code_pang/article/details/8263971 题意: ...

  6. POJ - 2109 Power of Cryptography(高精度log+二分)

    Current work in cryptography involves (among other things) large prime numbers and computing powers ...

  7. POJ 2109 Power of Cryptography 大数,二分,泰勒定理 难度:2

    import java.math.BigInteger; import java.util.Scanner; public class Main { static BigInteger p,l,r,d ...

  8. iOS项目double、float精度丢失解决办法

    描述 在iOS项目中老是遇到double.float精度丢失的问题 PS: NSString * jsonStr = @"{\"9.70\":9.70,\"67 ...

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

随机推荐

  1. Elastic Search的聚合搜索

    就是使用ES提供的aggs语法结果,使用DSL搜索的语法,实现聚合数据的统计,查询.ES中,如果新增document数据的时候,对应的index和type不存在,则自动创建. 1 准备源数据 PUT ...

  2. Keepalive+双主

    一.建立3台服务器之间ssh互信在mydb1,mydb2,mydb3服务器上分别执行:ssh-keygen -t rsassh-copy-id -i .ssh/id_rsa.pub root@192. ...

  3. Jmeter之cookie登录

    1.在web登录时,抓取登录的响应头 2.在jmeter中配置cookie HTTP Cookie管理器中添加信息 以下三个字段是必填的 3.添加HTTP请求(直接访问首页) 如果返回成功,并且响应内 ...

  4. 发明专利定稿&递交申请啦,开心

    也不想写些什么,只是想简单的分享一下当前的心情! 第一版到最后一版中间因为各种事情耽误,一直弄到现在.5月中旬找的专利代理局中间连续修改很多次,从大改到小改,再到微调真的是学习到了! 下面就是搞定&l ...

  5. UDP通信简单 小结

    Android手机版和电脑版 效果图: 通过WiFi局域网 电脑和手机连接通信. 电脑版本和手机版本使用了相同的消息发送头协议, 可以相互接收消息. 若有做的不好的地方还希望大家指导一下. 1. 手机 ...

  6. github常用搜索技巧

    1.在项目名称,readme文件和描述中包含关键字seckill的项目seckill in:name,readme,description 2.fork大于500,stars大于500springbo ...

  7. (三)创建基于maven的javaFX+springboot项目创建

    创建基于maven的javaFx+springboot项目有两种方式,第一种为通过非编码的方式来设计UI集成springboot:第二种为分离用户界面(UI)和后端逻辑集成springboot,其中用 ...

  8. OO方式实现ALV: cl_salv_table

    这里总结最近用cl_salv_table实现ALV遇到问题和解决办法 FORM set_alv2 . DATA: lv_syrepid TYPE syrepid. lv_syrepid = sy-cp ...

  9. 阿里云 elasticsearch 增删改查

    kibana 控制台 # 查询所有数据 GET /yixiurds_dev/_search { "query": { "match_all": { } } } ...

  10. rabbitmq 连接报错 An unexpected connection driver error occured

    转自:https://blog.csdn.net/zht741322694/article/details/82801873 在服务器上安装了一个RabbitMq,并新创建了一个用户授予了管理员角色, ...