hdu_1063,poj_1001_Exponentiation(大数,高精度) nyoj_155_求高精度幂

来源:互联网 发布:杭州萤石网络 点评 编辑:程序博客网 时间:2024/04/29 03:16
Exponentiation
Time Limit: 500MS Memory Limit: 10000KTotal Submissions: 121666 Accepted: 29731

Description

Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many computer systems.

This problem requires that you write a program to compute the exact value of Rn where R is a real number ( 0.0 < R < 99.999 ) and n is an integer such that 0 < n <= 25.

Input

The input will consist of a set of pairs of values for R and n. The R value will occupy columns 1 through 6, and the n value will be in columns 8 and 9.

Output

The output will consist of one line for each line of input giving the exact value of R^n. Leading zeros should be suppressed in the output. Insignificant trailing zeros must not be printed. Don't print the decimal point if the result is an integer.

Sample Input

95.123 120.4321 205.1234 156.7592  998.999 101.0100 12

Sample Output

548815620517731830194541.899025343415715973535967221869852721.0000000514855464107695612199451127676715483848176020072635120383542976301346240143992025569.92857370126648804114665499331870370751166629547672049395302429448126.76412102161816443020690903717327667290429072743629540498.1075960194566517745610440100011.126825030131969720661201

Hint

If you don't know how to determine wheather encounted the end of input:
s is a string and n is an integer
C++while(cin>>s>>n){...}cwhile(scanf("%s%d",s,&n)==2) //to  see if the scanf read in as many items as you want/*while(scanf(%s%d",s,&n)!=EOF) //this also work    */{...}

Source

East Central North America 1988


import java.math.BigDecimal;import java.util.Scanner;public class nyoj_155_求高精度幂 {//Accepted 3360K 188MS Java 424B 2013-08-30 21:25:53 public static void main(String[] args) {Scanner sc =new Scanner(System.in);while(sc.hasNext()){BigDecimal a = sc.nextBigDecimal();int b =sc.nextInt();a=a.pow(b);String s=a.stripTrailingZeros().toPlainString();if(s.startsWith("0."))s=s.substring(1);System.out.println(s);}}}


说明:
1、stripTrailingZeros() ,返回类型为BigDecimal的小于此数的但除去尾部的0的数值。
2、toPlainString(),返回BigDecimal类型的String类型字符串。
3、startsWith(),确定此实例的开头是否与指定的字符串匹配。
4、substring(),返回一个新的字符串,它是此字符串的一个子字符串。该子字符串始于指定索引处的字符,一直到此字符串末尾。