Poj 1001 High Precision power

Source: Internet
Author: User
Power of High Precision
Time limit:500 ms   Memory limit:10000 K
Total submissions:120785   Accepted:29494

Description

It is a very common problem to perform high-precision calculation on numbers with large numbers and high precision. For example, calculating national debt is a problem of this type.

The problem you want to solve now is: for a real number R (0.0 <r <99.999), The Write Program is required to accurately calculate the N power (RN) of R ), where N is an integer and 0 <n <= 25.

Input

T input includes multiple groups of R and N. The R value accounts for 1st to 6th columns, and the N value accounts for 8th and 9th columns.

Output

For each group of input, a row must be output, and the row contains the exact Nth Power of R. The output must be removed from the leading 0 and not 0. If the output is an integer, do not output the decimal point.

Sample Input

95.123 120.4321 205.1234 156.7592  998.999 101.0100 12

Sample output

548815620517731830194541.899025343415715973535967221869852721.0000000514855464107695612199451127676715483848176020072635120383542976301346240143992025569.92857370126648804114665499331870370751166629547672049395302429448126.76412102161816443020690903717327667290429072743629540498.1075960194566517745610440100011.126825030131969720661201

Source

 

Method 1

 

Import Java. io. *; import Java. math. bigdecimal; import Java. util. *;/** @ author denghuilong ** 2013-8-9 12:58:50 am **/public class main {public static void main (string [] ARGs) {consumer SC = new consumer (New bufferedinputstream (system. in); While (SC. hasnextbigdecimal () {bigdecimal r = SC. nextbigdecimal (); int n = SC. nextint (); string S = R. pow (n ). striptrailingzeros (). toplainstring (); If (S. charat (0) = '0') S = S. substring (1); system. out. println (s );}}}

Method 2

Quick power

 

Import Java. io. *; import Java. math. bigdecimal; import Java. math. biginteger; import Java. util. *; import sun. NIO. CS. ext. big5_solaris;/** @ author denghuilong ** 1:53:57 **/public class main {public static void main (string [] ARGs) {consumer SC = new consumer (New bufferedinputstream (system. in); While (SC. hasnextbigdecimal () {bigdecimal BD = SC. nextbigdecimal (); int n = SC. nextint (); bigdecimal B = POW (BD, N ); String S = B. striptrailingzeros (). toplainstring (); If (S. startswith ("0") {S = S. substring (1);} system. out. println (s) ;}}// fast power public static bigdecimal POW (bigdecimal BD, int N) {bigdecimal sum = bigdecimal. one; bigdecimal big = BD; while (n! = 0) {If (N & 1) = 1) {sum = sum. multiply (BIG);} big = big. multiply (BIG); N >>= 1;} return sum ;}}

 

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.