failing test cases
Fib gcd code doubt
@rohit_1906 hey, you are calculating Fib number in O(n) that will result in time out as the n can be very large.
Also this question utilizes a mathematical property:
GCD(Fib(A),Fib(B))=Fib(GCD(A,B))
So we need to form a seg tree on the array (not on Fibonacci number)
After number calculation we will need to use matrix exponentiation to get Fib number.
Here is efficient code:
your solution is giving tle for one test case
any better approach
just have one doubt … this code and previous one you sent are ditto same …i couldnt find any change but previous one gave tle …this one didnt…how??..if you have changed something please tell me at what line is the change