Hi,
I am able to calculate the Fibonacci sum of {0 - N } numbers. I cannot able to proceed further, How to calculate in Range of Fibonacci numbers.
Please check the code.
Thanks,
Pardeep Sharma.
Hi,
I am able to calculate the Fibonacci sum of {0 - N } numbers. I cannot able to proceed further, How to calculate in Range of Fibonacci numbers.
Please check the code.
Thanks,
Pardeep Sharma.
Just do fib(M+2) - fib(N+1)
Hi,
This method : fib(M+2) - fib(N+1) didn’t help.
To generate 0 to N Fibonacci numbers, I have taken F1 and T matrix as :
long[] F1 = {0, 1, 1};
long T[][] = new long[][]{{0, 1, 0}, {1, 1, 0}, {1, 1, 1}};
It works for 0-3 & 0-5 individually but for Range like 3-5, it fails
Please check or suggest if I am generating wrong matrix T.
Thanks.
How did you come up with this
long[] F1 = {0, 1, 1};
long T[][] = new long[][]{{0, 1, 0}, {1, 1, 0}, {1, 1, 1}};
long[] Fi or F1 = { f(0) , f(1), f(0) + f(1) }
long T[][] = new long[][]{{0, 1, 0}, {1, 1, 0}, {1, 1, 1}};
T . Fi = F i+1
Therefore F i+1 = { f(1), f(2), f(0) + f(1) + f(2) }
So,
F(n) = T ^ n . F1
This helps to generate sum of N fibonacci numbers.
Why don’t you use F(n+2)
- 1 for getting sum directly ?
Hi,
I’d some modification and able to pass example test cases in question.
But during submission, i can able to pass just one test case. I handled modulo operation too.
Please check.
Thanks
As I explained earlier, resultM - resultN
can be negative. So just do
(resultM - resultN)+MOD)%MOD
.