WA in COOKFOOD

I am calculating a expression k^2-3k+3 in two forms :
1.(k-1)^2-(k-2) and getting WRONG ANSWER

2.and by (k-2)^2+(k-1) and getting AC

Whats the internal process which is making this kind of conflict ??

problem :–

In this line:

long long int a2=(fast_exp1(k-1,2)-(k-2));

a2 can become negative. Suppose input n=2, k=31624, a2=-17500. Your output for that test case will be -800537500, which is incorrect I suppose.

When you are substracting by module you should write (if both b and c are already module MOD):

int a = ( b - c + MOD ) % MOD;
1 Like
//