ITKeyword,专注技术干货聚合推荐

注册 | 登录

uva 113 - Power of Cryptography

Frankiller 分享于 2012-06-14

推荐:Power of Cryptography

点击打开链接 Power of Cryptography Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 15247   Accepted: 7722 Description Current work in cry

2018阿里云全部产品优惠券(新购或升级都可以使用,强烈推荐)
领取地址https://promotion.aliyun.com/ntms/yunparter/invite.html


 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 tex2html_wrap_inline32 and an integer tex2html_wrap_inline34 you are to write a program that determines tex2html_wrap_inline36 , the positive tex2html_wrap_inline38 root of p. In this problem, given such integers n and p, p will always be of the form tex2html_wrap_inline48 for an integer k (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 tex2html_wrap_inline56 , tex2html_wrap_inline58 and there exists an integer k, tex2html_wrap_inline62 such that tex2html_wrap_inline64 .

The Output

推荐:poj2109 Power of Cryptography

Description Current work in cryptography involves (among other things) large prime numbers and computing powers of numbers among these primes. Work in

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

Sample Input

2
16
3
27
7
4357186184021382204544

Sample Output

4
3
1234

 

感觉double会有精度问题还是水过了。。

 

#include<stdio.h>
#include<math.h>
void main()
{double n,p;
 long left,right,mid;
 while (scanf("%lf%lf",&n,&p)!=EOF)
 {left=0; right=1000000000;
  while (left<right)
  {mid=(left+right)/2;
   if (pow(mid,n)==p) break;
   if (pow(mid,n)>p) right=mid;
   if (pow(mid,n)<p) left=mid;
  }
  printf("%d\n",mid);
 }
}

推荐:POJ 2109 Power of Cryptography

不知道那里贪心了。。。学长说贪心。 注意:数据类型范围,还是不太了解; 原题链接:http://poj.org/problemid=2109 Power of Cryptography Time Limit: 1000M

 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.

相关阅读排行


用户评论

游客

相关内容推荐

最新文章

×

×

请激活账号

为了能正常使用评论、编辑功能及以后陆续为用户提供的其他产品,请激活账号。

您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱

如果您没有收到激活邮件,请注意检查垃圾箱。