I've been playing with some code tonight and I coded a very simple algorithm that I think is a very good solution for a fibonacci recursive and for big numbers. I would like to know what you guys think about it and if you have any contribution for making it better, share with us... take a look at the code bellow
public class RecursiveFibonacci {
public void calculateFib(long first, long next, long counter, int n) {
if(counter == n) {
return;
}
counter++;
if(first == 0 && next == 0) {
System.out.println("0");
calculateFib(0, 1, counter, n);
return;
}
if(first == 0 && next == 1) {
System.out.println("1");
calculateFib(1, 0, counter, n);
return;
}
if(first == 1 && next == 0) {
System.out.println("1");
calculateFib(1, 1, counter, n);
return;
}
long result = first + next;
if(result > 1) {
System.out.println(result);
calculateFib(next, result, counter, n);
}
}
public RecursiveFibonacci() {
calculateFib(0, 0, 0, 9999999);
}
public static void main(String[] args) {
new RecursiveFibonacci();
}
}