Power of Cryptography 

Background

Current work in cryptography involves (among other things) large prime numbers and computing powers of numbers modulo functions of 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 of only theoretical interest.

This problem involves the efficient computation of integer roots of numbers.

The Problem

Given an integer  and an integer  you are to write a program that determines  , the positive root of p. In this problem, given such integers n and pp will always be of the form  for an integerk (this integer is what your program must find).

The 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  ,  and there exists an integer k such that  .

The Output

For each integer pair n and p the value  should be printed, i.e., the number k such that  .

Sample Input

2
16
3
27
7
4357186184021382204544

Sample Output

4
3
1234

double能表示的范围是-1.7e308 ~ 1.7e308,精度至少为15位,而输出结果在int的范围内,即10位,所以可以输出可以用double

至于计算过程中为什么能用double而不会影响到结果,我也暂时没搞懂,因为double的精度只有15位,最多也才有16位,但是p的范围是10^101,输入过程中用的也不是科学计数法,15位后的值肯定被抹掉了,结果却是对的。

正确的分析应该在这:http://blog.csdn.net/synapse7/article/details/11672691,用到了误差分析,得出的结果是在这一题里失去的精度不会影响答案,等我数学补上来之后来研究(吐槽一下网上的好多人,风轻云淡的就发上来了,真的懂了么?自己不扎实不要紧,关键在于误导了新手)

 #include<stdio.h>
#include<math.h> int main(void)
{
double n,p; while(scanf("%lf%lf",&n,&p) != EOF)
printf("%.lf\n",pow(p, / n)); return ;
}

UVA 113 Power of Cryptography (数学)的更多相关文章

  1. POJ-2109 Power of Cryptography(数学或二分+高精度)

    题目链接: https://vjudge.net/problem/POJ-2109 题目大意: 有指数函数 k^n = p , 其中k.n.p均为整数且 1<=k<=10^9 , 1< ...

  2. Power of Cryptography(用double的泰勒公式可行分析)

    Power of Cryptography Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onli ...

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

  7. POJ2109——Power of Cryptography

    Power of Cryptography DescriptionCurrent work in cryptography involves (among other things) large pr ...

  8. uva 10330 - Power Transmission(网络流)

    uva 10330 - Power Transmission 题目大意:最大流问题. 解题思路:増广路算法. #include <stdio.h> #include <string. ...

  9. UVA 11149 - Power of Matrix(矩阵乘法)

    UVA 11149 - Power of Matrix 题目链接 题意:给定一个n*n的矩阵A和k,求∑kiAi 思路:利用倍增去搞.∑kiAi=(1+Ak/2)∑k/2iAi,不断二分就可以 代码: ...

随机推荐

  1. Unity中的C#规则

    命名 文件名和Class要一致(CamelCase) 类公共和保护类型Property(CamelCase) 类的公共和保护类型Fields(CamelCase)* 先采用.Net的命名方法,如果出现 ...

  2. Android 通过xml 自定义图片

    <?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http:/ ...

  3. Python学习入门基础教程(learning Python)--5.2 Python读文件基础

    上节简单的说明了一下Pyhon下的文件读写基本流程,从本节开始,我们做几个小例子来具体展示一下Python下的文件操作,本节主要是详细讲述Python的文件读操作. 下面举一个例子,例子的功能是读取当 ...

  4. SMARTFORM报表程序设计(1)

    SMARTFORM是SAP提供的一款商务单据及报表设置工具,可以在FORM中实现数据的计算及转换等功能,并能在FORM创建的同时生成功能模块,为FORM和ABAP程序提供更为强大的参数接口.输入T-C ...

  5. 从头学Android系列

    从头学Android系列 http://blog.csdn.net/worker90/article/category/888358

  6. [Angular2 Form] Group Inputs in Angular 2 Forms with ngModelGroup

    The ngModelGroup directive allows you to group together related inputs so that you structure the obj ...

  7. C++中临时对象的学习笔记

    http://www.cppblog.com/besterChen/category/9573.html 所属分类: C/C++/STL/boost  在函数调用的时候,无论是参数为对象还是返回一个对 ...

  8. Android开发目录

    1.ADT下载地址整理 2.之前的Android项目报错,新建Android项目报错,代码中找不到错误解决方案 3.错误“Unexpected namespace prefix "xmlns ...

  9. css中postion的fixed与absolute区别详解

    fixed:固定定位,参照位置是浏览器窗口的左上角,即坐标点为(0px, 0px) absolute:绝对定位,参展位置是离当前元素最近的定位方式为fixed,absolute,relative的祖先 ...

  10. redis源码学习

    上帝禁区  http://blog.csdn.net/a600423444/article/details/8944601