Could someone please point out my mistake ?
you can try 6 4
the ans should be 2
Shouldn’t the answer be 7 for 6 4 ? @ram_24
yeah you are right…Actually the problem is in a[i]=(((2*(a[i-1]%mod))%mod)-1)%mod; You shouldn’t do -1 rather you should subtract the a[i-k-1]th term from the exp… because the ith term will consist of last k terms and the (i+1)th term will contain its last k term which can easily be obtained by a[i]=((((a[i-1]+a[i-1])%mod)-a[i-k-1])%mod+mod)%mod;
Okay, I’ll try with that change. Also, why did you use (+mod) in your modified equation ?
I tweaked the formula a little by adding a case. If i-k-1>k, I used a[I-k-1] else I subtracted 1. Thank you for the help. @ram_24