WA on FIBTWIST SPOJ

Getting WA on spoj …all test cases passes sample and around 8-9 there also passed.

Hi @piyush.bansal8158625
in dis question also, try taking fibonacci from 0.
else u can try using this formulae

calculate_fibonacci_matrix(fib, n+1);
long long fn = fib[0][1], fn_1 = fib[1][1];

    int sum = (2*(fn-1) + 2*fn_1 - n) % MOD;
    if (sum < 0) sum += MOD;

Hope dis helps.

I just corrected the code and it failied too…I replied on ur previou post
I didn’t get ur sum part…ur brackets and underscores mixed up
For getting fib[1][1] i called it again having power n as it will give the same term


and last how these relations are coming… it proves but how to guess it myself

@piyush.bansal8158625
its always prefered to get the basic approach to calculate transformation matrix. Deriving such formula can sometimes take a min and sometimes even a day. So, its better to follow the basic approach that prateek bhaiya must have told to form transformation matrix in these cases.like f(n)=f(n-1)+n-1,etc.

For the previous post i didnt get ur question, try messaging ur doubt in chat.
Hope dis help

I have mdofied the code but still getting worng answer…used ur relation but still fails.

I didn’t knew when a non constant term is added to a recurrence. Prateek bhaiya in live class told about basic case,constant term ,and series sum if required. U can share any image for the n-1 term which is being added and how to build matrix for same. Or any link

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.