I am attempting to find the first number in the fibbonacci sequence to contain N digits (N being somewhere in the range of 500 and 2000). I attempt to do this with the following code:
BigInteger num = BigInteger.valueOf(2);
BigInteger num1 = BigInteger.ONE;
BigInteger num2 = BigInteger.ONE;
int record = 0;
BigInteger TEN = BigInteger.valueOf(10);
public BigInteger run()
{
BigInteger temp = BigInteger.ZERO;
while(num2.compareTo(TEN.pow(SomeN - 1)) < 0)
{
if(num2.compareTo(TEN.pow(record + 1)) >= 0)
{
System.out.println(""+record);
record++;
}
temp = num1.add(num2);
num1 = num2;
num2 = temp;
num = num.add(BigInteger.ONE);
}
System.out.println(""+num);
System.out.println(""+num2);
return num2;
}
The problem is, when I test for, say 1500 digits, the answer I get is apparently wrong. I do not know what the answer is supposed to be, and I have even checked the answers immediately around it in case my algorithm is off by a power of 10 (ie. I checked 1499 digits and 1501), but to no avail. Anyone see what is wrong?