BigInteger in Java

Source: Internet
Author: User
Tags pow

Header file

Import java.io.*;

Import java.math.*;

Read in

Scanner cin = Scann (system.in);

while (Cin.hasnext ()) <->!=eof

n = cin.nextint (); <-> read in an int number

n = Cin.nextbiginterger (); <-> read into a large integer

Output

SYSTEM.OUT.PRINTLN (n); Print n

System.out.println (); Line break

System.out.printf ("%d\n", N); can also be similar to the output mode in C + +

Defined:

int i,j,k,a[];

A = new int[100];

BigInteger n,m;

BigDecimal N;

String s;

Data type:

Data type type fame Long value range default value

Boolean 1 True,false False

BYTE type byte 8-128-127 0

Character Char-' \u000 '-\uffff ' \u0000 '

Short-16-32768-32767 0

Integer int 32-2147483648,2147483647 0

Long 64-9.22e18,9.22e18 0

float Float-1.4e-45-3.4028e+38 0.0

Double-4.9e-324,1.7977e+308 0.0

BigInteger arbitrarily large integers, in principle, as long as your computer's memory is large enough to have unlimited digits

BigInteger arbitrary large real numbers, can handle decimal precision problems.

Some common functions in BigInteger are:

A=biginteger.one

B=biginteger.ten

C=biginteger.zero

Some common numbers are assigned initial values. Assigns the number of int type to biginteger,biginteger.valueof (k);

Basic functions:

VALUEOF: Assigning an initial value

add:+ A.add (b);

subtract:-

multiply:*

divide:/

Remainder:this% val

Divideandremainder:a[0]=this/val; A[1]=this% val

Pow:a.pow (b) =a^b

Gcd,abs: Number of conventions, absolute value

Negate: Take negative numbers

Signum: Symbolic functions

Mod:a.mod (b) =a%b;

Shiftleft: Shift left, this << N, this*2^n;

Shiftright: Shift Right, this >> n,this/2^n;

And: equivalent to C + + &&

or:| |, or;

XOR: XOR, BigInteger xor (BigInteger val), This^val

not:!, non-;

Bitlength: Returns the number of bits represented by the smallest twos complement of this digit, that is, * does not include the * sign bit (ceil (log2 (this <0?-this:this + 1)). For positive numbers, this is equivalent to the number of bits in the normal binary representation.

Bitcount: Returns the number of bits in the binary complement representation of the digit that do not pack the spread symbol bit. This method is useful for implementing bit-vector-style collections on top of bigintegers.

Isprobableprime: Returns True if the BigInteger is likely to be a prime number, or False if it is explicitly a composite. Parameter certainty is a measure of uncertainty that the caller is willing to endure: if the probability of the number being a prime is greater than the 1-1/2**certainty method, the method returns True. The execution time is proportional to the value of the parameter certainty.

CompareTo: Based on the value is less than, equal to, or greater than Val returns-1, 0, or 1;

Equals: Judge whether two number is equal, can also use CompareTo to replace;

Min,max: Take two numbers of smaller, larger people;

Intvalue,longvalue,floatvalue,doublue: Converts this number to the value of the number of that type.

BigInteger in Java

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.