document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package fibonacci;
  2. import java.math.BigInteger;
  3.  
  4. /*
  5.  ===========================================================================
  6.  Author      : Catarina Moreira
  7.  Copyright   : Catarina Moreira all rights reserved
  8.  Description : Implementation of the fibonacci sequence using a fast recursive
  9.                algorithm
  10.  ===========================================================================
  11. */
  12. public class RecursiveFast extends Fibonacci
  13. {
  14.     public BigInteger runFibonacci( int n )
  15.     {
  16.         if( n == 0)
  17.        return BigInteger.ZERO;
  18.        
  19.     if( n == 1)
  20.        return BigInteger.ONE;
  21.        
  22.     return auxFibonacci( n, BigInteger.ZERO, BigInteger.ONE );
  23.     }
  24.  
  25.     public BigInteger auxFibonacci( int n, BigInteger val1, BigInteger val2 )
  26.     {
  27.         if( n == 1 )
  28.        return val2;
  29.    
  30.         return auxFibonacci( n - 1, val2, val1.add( val2 ));
  31.     }
  32. }
');