uva156

来源:互联网 发布:淘宝买家申请售后换货 编辑:程序博客网 时间:2024/06/08 16:59

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=49

113 - Power of Cryptography

Time limit: 3.000 seconds


Power of Cryptography

Background

Current work in cryptography involves (among other things) largeprime numbers and computing powers of numbers modulo functions ofthese primes. Work in this area has resulted in the practical useof results from number theory and other branches of mathematicsonce considered to be of only theoretical interest.

This problem involves the efficient computation of integer rootsof numbers.

TheProblem

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 suchintegers n and p, p will always be of the formtex2html_wrap_inline48 for an integer k (this integer is what yourprogram must find).

TheInput

The input consists of a sequence of integer pairs n andp with each integer on a line by itself. For all such pairstex2html_wrap_inline56 , tex2html_wrap_inline58 and there exists an integer k, tex2html_wrap_inline62 such that tex2html_wrap_inline64 .

TheOutput

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

SampleInput

21632774357186184021382204544

SampleOutput

431234
这题其实是考察人的逆向思维。。。有点trick
#include<stdio.h>
#include<math.h>
int main()
{
 int k,i;
 double p,n;
 while(scanf("%lf %lf",&n,&p)!=EOF)
 {
  printf("%.lf\n",pow(p,1/n));//强制转化成int的话会有误差,可以用floor试试
 }
 return 0;
原创粉丝点击