UVA 113: Power of Cryptography

Jasonlin posted @ 2011年3月28日 10:49 in UVA , 2684 阅读

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=3&problem=49&mosmsg=Submission+received+with+ID+8686160

题目大意:

     一个数k的n次方等于p,给你n和p求出k。tex2html_wrap_inline56 , tex2html_wrap_inline58

解题思路:

     看到数据范围吓到了,难道是高精度?难度要用JAVA高精度?才头几题有必要这么可怕?后来实在不行了,看解题报告,看一下吐血,float的范围为-2^128 ~ +2^127,也即-3.40E+38 ~ +3.40E+38;double的范围为-2^1024 ~ +2^1023,也即-1.79E+308 ~ +1.79E+308。所以只要用double和pow就行~还用了下C++精度控制。

解题代码:

#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main(){
    double n,p;
    while(cin>>n>>p){
        cout<<fixed<<setprecision(0)<<pow(p,1/n)<<endl;
    }
    return 0;
}

 

扩展知识:http://edu.gamfe.com/tutor/d/20330.html

  • 无匹配
  • 无匹配

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter