exponentiation
Time limit:2000/500 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 9107 Accepted Submission (s): 2654
Problem descriptionproblems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt are a taxing experience for many computer systems.
This problem requires so 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 a integer such that 0 < n <= 25.
Inputthe input would consist of a set of pairs of values for R and N. The R value would occupy columns 1 through 6, and the N value would be in columns 8 and 9.
Outputthe output would consist of one line for each line of input giving the exact value of r^n. Leading zeros should is Su Ppressed in the output. Insignificant trailing zeros must not being printed. Don ' t print the decimal point if the result was an integer.
Sample Input95.123 120.4321 205.1234 156.7592 998.999 101.0100 12
Sample Output548815620517731830194541.899025343415715973535967221869852721.00000005148554641076956121994511276767154838481760200 72635120383542976301346240143992025569.92857370126648804114665499331870370751166629547672049395302429448126.7641210216181 6443020690903717327667290429072743629540498.1075960194566517745610440100011.126825030131969720661201
Source East Central North America 1988 test instructions calculates how many times a floating-point number is power. Code: Write a question in Java for the first time. High precision Real class BigDecimal in Java.
BigDecimal Add (BigDecimal augend): addition
BigDecimal Subtract (BigDecimal subtrahend): Subtraction
BigDecimal Divide (BigDecimal divisor): Division
BigDecimal pow (int n): the
BigDecimal Multiply (BigDecimal multiplicand): multiplication
BigDecimal Striptrailingzeros () returns a value that is superior to this decimal, but removes all trailing zeros from that representation BigDecimal.
BigDecimal toplainstring () returns the string representation of this BigDecimal without a reference to a number field. is to show directly, without scientific notation.
2 ImportJava.util.Scanner;3 ImportJava.math.BigDecimal;4 Public classMain {//is named in main to compile on OJ5 Public Static voidMain (string[] args) {6Scanner cin=NewScanner (system.in);7 while(Cin.hasnext ()) {8BigDecimal a=cin.nextbigdecimal ();9 intb=cin.nextint ();TenString s=A.pow (b). Striptrailingzeros (). toplainstring (); One if(S.charat (0) = = ' 0 ') AS=s.substring (1); - System.out.println (s); - } the } -}
HDU1063 large number of Java