bench-fibo

Unnamed repository; edit this file 'description' to name the repository.
git clone https://logand.com/git/bench-fibo.git/
Log | Files | Refs | README

fibo40.java (499B)


      1 import java.math.BigInteger;
      2 
      3 class fibo40 {
      4 
      5     final static BigInteger one = BigInteger.ONE;
      6     final static BigInteger two = BigInteger.ONE.add(one);
      7     final static BigInteger three = BigInteger.ONE.add(two);
      8 
      9     final static BigInteger fibo(BigInteger n) {
     10         if(-1 == n.compareTo(three)) return n;
     11         else return fibo(n.subtract(one)).add(fibo(n.subtract(two)));
     12     }
     13 
     14     public static void main(String args[]) {
     15         System.out.println(fibo(new BigInteger("40")));
     16     }
     17 }