Acm_exponentiation (Java High precision)

Source: Internet
Author: User

Exponentiationtime limit:2000/1000ms (java/others) problem Description:
Problems 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.
Input:
The 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.
Output:
The output would consist of one line for each line of input giving the exact value of r^n. Leading zeros should is suppress Ed in the output. Insignificant trailing zeros must not being printed. Don ' t print the decimal point if the result was an integer.
Sample Input:
95.123 120.4321 205.1234 156.7592  998.999 101.0100 12
Sample Output:
548815620517731830194541.899025343415715973535967221869852721.00000005148554641076956121994511276767154838481760200726351 20383542976301346240143992025569.92857370126648804114665499331870370751166629547672049395302429448126.7641210216181644302 0690903717327667290429072743629540498.1075960194566517745610440100011.126825030131969720661201
Problem-solving ideas: Calculate r^n, requirements: ① If the whole number of parts is divided into 0, remove the integer part; ② remove all 0,java water from the end of the result!
AC Code:
1 ImportJava.math.BigDecimal;2 ImportJava.util.Scanner;3  Public classMain {4      Public Static voidMain (string[] args) {5Scanner scan =NewScanner (system.in);6          while(Scan.hasnext ()) {7BigDecimal BD =NewBigDecimal (Scan.next ());8BigDecimal result =Bd.pow (Scan.nextint ());9             //How to use Striptrailingzeros (): Returns a value that is superior to this decimal, but removes all trailing zeros from this representation BigDecimal. Ten             //How to use Toplainstring (): Returns the string representation of this bigdecimal without a reference to a number field.  OneString obj =Result.striptrailingzeros (). toplainstring (); A             //startsWith (String prefix): Tests whether this string starts with the specified prefix. This means that if the integer part is divided into 0, the sub-string with the subscript 0 is truncated. -             if(Obj.startswith ("0")) obj=obj.substring (1); - System.out.println (obj); the         } -     } -}

Acm_exponentiation (Java High precision)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.