Created
July 3, 2015 22:47
-
-
Save fmamud/2667b5249d73766fa131 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package forkjoin; | |
import java.math.BigInteger; | |
public class FibonacciProblem3 { | |
BigInteger n; | |
public FibonacciProblem3(int n) { | |
this.n = BigInteger.valueOf(n); | |
} | |
public BigInteger solve() { | |
return fibonacci(n); | |
} | |
private BigInteger fibonacci(BigInteger n) { | |
BigInteger previous = BigInteger.valueOf(-1), result = BigInteger.ONE; | |
for (long i = 0; BigInteger.valueOf(i).compareTo(n) <= 0; i++) { | |
BigInteger sum = result.add(previous); | |
previous = result; | |
result = sum; | |
} | |
return result; | |
} | |
public BigInteger getN() { | |
return n; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment