Java Large number Operation
Some applications of large Java integers:
import java.util.*;
import java.math.*;
Public class main{
Public static void main (String args[]) {
Scanner cin = new Scanner (system.in);
BigInteger A, B;
End With file EOF
while (Cin.hasnext ()) {
A = Cin.nextbiginteger ();
b = Cin.nextbiginteger ();
System.out.println (A.add (b)); Large integer Addition
System.out.println (A.subtract (b)); Large integer Subtraction
System.out.println (a.multiply (b)); Large integer Multiplication
System.out.println (A.divide (b)); Large integer division (rounding)
System.out.println (A.remainder (b)); Large integer Modulo
Comparison of large integers
if (A.compareto (b) = = 0) System.out.println ("a = = B"); Large integer a==b
else if (A.compareto (b) > 0) System.out.println ("a > B"); Large integer a>b
else if (A.compareto (b) < 0) System.out.println ("a < B"); Large integer a<b
Large integer Absolute value
System.out.println (A.abs ()); Absolute value of large integer A
The power of a large integer
int exponent=10;
System.out.println (A.pow (exponent)); The exponent power of large integer A
Returns a string representation of a large integer decimal
System.out.println (A.tostring ());
Returns a string representation of a large integer P-system
int p=8;
System.out.println (A.tostring (p));
}
}
}