I am getting error time limited exceeded.
code link:
Spp recursive sequence
Hey your code has very high time complexity O(t(n-m)). And n - m could be upto 10^18 which makes this solution infeasible.
for(int i=n ;i<=m ;i++){
ans = ((ans%MOD)+ (compute(i)%MOD))%MOD;
}
What you should have done is find sum of first n elements and find sum of first m - 1 elements. And subtract them to get sum of element in range(m, n). You need to find the sums using matrix exponentiation (O(logn)) time.
can you share your code
Or you can also see this.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.