Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigInteger;
- import static java.math.BigInteger.ZERO;
- import static java.math.BigInteger.ONE;
- public class Fibonacci {
- private static final BigInteger TWO = new BigInteger("2");
- public static BigInteger fib(BigInteger n) {
- if(n.equals(ZERO))
- return ZERO;
- else if(n.equals(ONE))
- return ONE;
- else
- return fib(n.subtract(ONE)).add(fib(n.subtract(TWO)));
- }
- private static BigInteger fib(int n, int i, BigInteger f1, BigInteger f2) {
- if(i == n)
- return f1.add(f2);
- return null;
- }
- public static BigInteger fib(int n) {
- return fib(n, 0, ZERO, ONE);
- }
- public static void main(String[] args) {
- System.out.println(fib(new BigInteger("20000000")));
- }
- }
Add Comment
Please, Sign In to add comment