On BigInteger usage in Java

Source: Internet
Author: User
Tags greatest common divisor pow

1. Assign values:

BigInteger a=new BigInteger ("1");

BigInteger b=biginteger.valueof (1);

2. Operation:

①add (); Add large integers
BigInteger a=new BigInteger ("23");
BigInteger b=new BigInteger ("34");
A. Add (b);

②subtract (); Subtraction
③multiply (); Multiply
④divide (); Divide rounding
⑤remainder (); Take surplus
⑥pow (); A.pow (b) =a^b
⑦GCD (); Greatest common divisor
⑧abs (); Absolute
⑨negate (); Take the inverse number
⑩mod (); A.mod (b) =a%b=a.remainder (b);

3.BigInteger Constructors:
Generally used in the following two kinds:
BigInteger (String val);
Converts the specified string to a decimal representation;
BigInteger (String val,int radix);
Converts the string representation of a BigInteger of a specified cardinality to BigInteger
4. Basic constants:
A=biginteger.one 1
B=biginteger.ten 10
C=biginteger.zero 0

5.n.compareto (Biginteger.zero) ==0//equivalent to N==0

6.if (A[i].compareto (n) >=0 &&a[i].compareto (m) <=0)//A[i]>=n && a[i]<=m

1 ImportJava.math.BigInteger;2 ImportJava.util.Scanner;3 4  Public classMain {5     6      Public Static voidMain (string[] args) {7BigInteger sum =NewBigInteger ("1");8Scanner input =NewScanner (system.in);9          while(true)Ten         { OneBigInteger num =Input.nextbiginteger (); A             if(num equals (Biginteger.zero)) Break; -             Elsesum =sum.multiply (num); -         } the         intCNT = 0; - System.out.println (sum); -          while(true ) -         { +biginteger[] bis =Sum.divideandremainder (biginteger.ten); -             if(bis[1].equals (Biginteger.zero)) +             { Acnt++; atsum = bis[0]; -             } -             Else  Break; -              -              -         } in System.out.println (CNT); -              to      +  -     } the}

On BigInteger usage in Java

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.