# Big Number problem in JAVA in programming contest

Bignumber problem can be solved easily using BigInteger class in java.Here is a sample for doing this….
[code]
import java.math.BigInteger;

public class BIG
{
public static void main(String[] args)
{
//initialization
BigInteger N1 = new BigInteger ("1000000000000000000");
BigInteger N2 = new BigInteger ("123456789123");
BigInteger N3 = new BigInteger ("50000000000");
//Math operations
BigInteger mult = N1.multiply(N2); //This is how to send arguments in bigint functions
BigInteger div= N1.divide(N2);
BigInteger substract1 = N1.subtract(N2); //N1-N2
BigInteger substract2 = N2.subtract(N1); //N2-N1
BigInteger gcd = N1.gcd(N3);
//Printing output
System.out.println("Mult " + mult);
System.out.println("div " + div);
System.out.println("substract1 " + substract1);
System.out.println("substract2 " + substract2);
System.out.println("gcd N1 N3 " + gcd);
}
}
[/code]
There are some more built in functions:

BigInteger.ONE; (==1)
BigInteger.ZERO;(==0)
A.abs();
A.divide(N);
A.divideAndRemainder(N); (returns an array)
A.max(N);
A.min(N);
A.mod(N);
A.multiply(N);
A.remainder(N);
A.signum(N);

A.doubleValue();
A.floatValue();
A.intValue();
A.longValue();
A.toString();
A.compareTo(N)

converting an integer to bigint
BigInteger A = BigInteger.valueOf(20000);
You can take input using scanner just as you input int,long etc.

## 2 Replies to “Big Number problem in JAVA in programming contest”

1. জাভা নিয়ে টেনশান নাই। আপনার টিউটেরিয়াল পামু 🙂

2. oi vabe serially paba na..somossa hoile ekhane req diyo..lekhe dibo ni…