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. 模仿ORM

    ORM 对象关系映射 类 ---------->映射--------->    表 对象 ------>映射---------->   一条记录 对象点属性 --->映射 ...

  2. luffy后台相关设置

    目录 项目创建 环境 创建项目 重构项目目录 配置开发环境 配置日志 环境变量 dev.py 在写项目直接导入utils文件夹也不''错误提示'' 封装logger dev.py utils/logg ...

  3. flask项目配置

    config.py: class Config(object): """项目的配置""" DEBUG = True SECRET_KEY = ...

  4. springboot打包的jar项目,不需要安装jdk环境启动

    因为服务器上是JDK7,而springboot至少用JDK8才行,但是又因为是很老的项目,不是很清楚能不能换JDK8,有风险,因此选择以前项目用JDK7,而新的springboot用JDK8.步骤一: ...

  5. Web项目测试流程总结

    个人知识脑图总结 - 未完全(工作项目脑图总结存于网盘中)

  6. .Net面试题四

    1.C#编译成的dll存放在哪个目录?C#程序文件的后缀名是什么?.csproj后缀名是什么文件? 2.请写出C#中常用文件操作类.数据库操作类.网络请求类.每项至少写出三个 3.请定义一个只读属性: ...

  7. Cognex925B的使用方法

    一.Cognex925B的简介                                           Cognex925B是一款线激光扫描传感器,利用激光三角的原理测量Z方向的断差. 二 ...

  8. 第十章、jupyter入门之pandas

    目录 第十章.jupyter入门之pandas 一.什么是pandas 二.Series 三.基本概念 四.基本运算 五.DataFrame 第十章.jupyter入门之pandas 一.什么是pan ...

  9. ath6kl 架构

    转:http://blog.csdn.net/robertsong2004/article/details/38899415 AR600x软件被划分为主机端和目标端软件.主机端软件或驱动程序的代码被提 ...

  10. pandas中的Series

    我们使用pandas经常会用到其下面的一个类:Series,那么这个类都有哪些方法呢?另外Series和DataFrame都继承了NDFrame这个类,df.to_sql()这个方法其实就是NDFra ...