fib(400000)

Java's BigInteger: 4s

My implementation: 11s

If anyone wants to see my implementation, and maybe have some improvements then be free to answer Also ask if you have any questions. Basically it is one big int array where the indexes combined is one big number. Also the number is reversed in the array

public class MyBigIntegerThree { private final int base = Integer.MAX_VALUE; //Contains the max value each index private int[] bigNumber; public MyBigIntegerThree( int number ) { bigNumber = new int[1]; bigNumber[0] = number; } public int[] add( int[] other ) { int bigNumberLength = bigNumber.length; int otherLength = other.length; int[] result = new int[bigNumberLength >= otherLength ? bigNumberLength : otherLength]; //Setting length to the biggest long carry = 0; for ( int i = 0; i < result.length; i++ ) { if ( i >= bigNumberLength ) { long sum = (long) other[i] + carry; carry = sum / base; result[i] = ((int) (sum % base)); } else if ( i >= otherLength ) { long sum = (long) bigNumber[i] + carry; carry = sum / base; result[i] = ((int) (sum % base)); } else { long sum = (long) bigNumber[i] + (long) other[i] + carry; carry = sum / base; result[i] = ((int) (sum % base)); } } while ( carry != 0 ) { //expands array by 1 int[] temp = new int[result.length + 1]; System.arraycopy( result, 0, temp, 0, result.length ); temp[temp.length - 1] = (int) (carry % base); result = temp; carry = (int) (temp[temp.length - 1] / base); } return bigNumber = result; } public int[] getArray() { return bigNumber; } public void setArray( int[] array ) { this.bigNumber = array; } public String toString() { StringBuffer string = new StringBuffer(); for ( int i = bigNumber.length - 1; i >= 0; i-- ) { string.append( bigNumber[i] * Math.pow( base, i ) + " + " ); } return string.toString(); } }

EDIT: Corrected the code

This post has been edited by **CasiOo**: 09 June 2011 - 03:48 PM