Hello everybody ..
This is the first time i post on to daniweb for a favour.
Am just proceeding with a math contest.
in general say n , need the catalan series with formula 2n!/(n!*(n+1)!) . i am in need of the answer for n=1000.
I thought cud try this in java with the help of bigint. but in vain .. the answer might near 600 digits.. can someone help me ?
Thanx in advance

Recommended Answers

All 5 Replies

AFAIK BigInteger will handle as many digits as you have memory for, certainly 600 is OK.

AFAIK BigInteger will handle as many digits as you have memory for, certainly 600 is OK.

i guess am running out of memory ...

No way.
BigInteger stores the number in normal binary form, using an array of ints big enough to hold all the bits for the number. At approx 10 decimal digits for each int, your 600 digit number only needs array approx int[60]. I don't think 240 bytes is going to run you out of memory - your problem lies elsewhere. Anyway, you get an explicit runtime Exception when you run out of memory.
Can you share your code?

No way.
BigInteger stores the number in normal binary form, using an array of ints big enough to hold all the bits for the number. At approx 10 decimal digits for each int, your 600 digit number only needs array approx int[60]. I don't think 240 bytes is going to run you out of memory - your problem lies elsewhere. Anyway, you get an explicit runtime Exception when you run out of memory.
Can you share your code?

Hey thanx got it :) this was ma code made a mistake in ma calculation only.. Thank u :)

import java.math.BigInteger;
public class kuruk {
    public static void main(String[] args) {
        BigInteger thou=new BigInteger("1000");
BigInteger thou1=new BigInteger("1001");
BigInteger twot=new BigInteger("2000");
        //-- BigInteger solution.
        BigInteger n = BigInteger.ONE;
        for (int i=1; i<=2000; i++) {
            n = n.multiply(BigInteger.valueOf(i));
	if(i==2000 || i==1000 ||i==1001)
        //    System.out.println(i + "! = " + n);
	if(i==1000)
		thou=n;
	if(i==1001)
		thou1=n;
	if(i==2000)
		twot=n;
        }
	thou=thou.multiply(thou1);
	twot=twot.divide(thou);
	System.out.println(twot);

    }
}

OK. Time to mark this thread as solved?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.