51nod 1873 Junior's Arithmetic "Java bigdecimal/high Precision decimal"

Source: Internet
Author: User

1873 Math Base time limit for junior High: 1 seconds Space limit: 131072 KB Score: 10 Difficulty: 2-level algorithm topic collection attention

Noder now on the third day, is beginning to review the examination. He had to calculate the type every day as(AX ax ax ? X a )n A The formula. which 0.0<a<99.999,0<n< .

Although Noder will calculate, but is always wrong, now he wants you to write a program to output the correct results for him to check.

Input
A single set of test data. The first line has a real number A and an integer n, and the middle is separated by a space. 0.0 < A < 99.999,a always occupies 6 bits (a length <=6), 0<n<26.
Output
Output a real number to indicate the result, do not output leading 0, after the extra 0 also do not output, if it is an integer do not output a decimal point.
Input example
Sample input 10.4321 20 sample input 21.0100 12
Output example
Sample output 1.00000005148554641076956121994511276767154838481760200726351203835429763013462401 Sample output 21.126825030131969720661201

"Code":
ImportJava.util.*;Importjava.math.*;ImportJava.math.BigDecimal;ImportJava.util.*; Public classMain { Public Static voidMain (String args[]) {Scanner cin=NewScanner (system.in); DoubleA =cin.nextdouble (); intn =Cin.nextint (); BigDecimal ans=NewBigDecimal ("1");  for(inti = 0; I < n; i++) ans=ans.multiply (Bigdecimal.valueof (a)); String s=Ans.striptrailingzeros (). toplainstring (); intI=0; if(S.charat (0) = = ' 0 ' &&s.charat (1) = = '. ') I=1;  for(; I<s.length (); i++) System.out.print (S.charat (i)); }}
Java

51nod 1873 Junior's Arithmetic "Java bigdecimal/high Precision decimal"

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.