Showing posts with label Fibonacci having 1000 digits. Show all posts
Showing posts with label Fibonacci having 1000 digits. Show all posts

Monday, February 6, 2012

Fibonacci term no having 1000 digits








import java.math.BigInteger;

/*
 * bhatt.umang7@gmail.com
 */
/**
 @author umang
 */
public class Fib
{
    
    public static void main(String args[])
    {
        BigInteger prev_prev = new BigInteger("0");
        BigInteger prev = new BigInteger("1");
        BigInteger sum = prev_prev.add(prev);
        long i = // as 1 should already be there
        while (sum.toString().length() 1000)
        {
            sum = prev_prev.add(prev);
            prev_prev = prev;
            prev = sum;
            i++;
            System.out.println(i + " is " + sum.toString());
        }
        System.out.println(i);
        
    }
}