Java Large number calculation

Source: Internet
Author: User

These days to do a few words with a large number of questions, found that Java to larger number of operations is very convenient. It's very practical for acmer.

1 ImportJava.io.*;2 ImportJava.math.BigInteger;3 ImportJava.util.*;4  Public classMain {5 6      Public Static voidMain (string[] args) {7         //TODO auto-generated Method Stub8Scanner cin=NewScanner (NewBufferedinputstream (system.in));9PrintWriter cout=NewPrintWriter (System.out);Ten         intT; Onet=cin.nextint (); A         intEg=1; -          while(t>0) -         { theBigInteger eight=NewBigInteger ("8"); -BigInteger seven=NewBigInteger ("7"); -BigInteger one=NewBigInteger ("1"); - String INP; +inp=Cin.next (); -BigInteger n=NewBigInteger (INP); + BigInteger ans; A BigInteger ans2; atans=n.multiply (n). Multiply (eight); -Ans2=N.multiply (seven); -ans=ans.subtract (ANS2); -ans=Ans.add (one); -Cout.println ("Case #" +eg+ ":" +ans); -++eg; in--T; -              to         } + Cout.flush (); -     } the  *}

All calculations of a large number are made between large numbers

BIgInteger A, B;

A=a.add (b);

A=a.substract (b);

A=a.multiply (b);

A=a.divied (b);

A=A.GCD (b);

Java Large number calculation

Related Article

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.