CHFING-Concept used

Yep! you can refer this link :- Modular multiplicative inverse - GeeksforGeeks

Hello !
I am getting WA on TASK#1 (sub task 2).Can someone tell me where i am wrong ?

Solution Link : - CodeChef: Practical coding for everyone

a small trick for division with small numbers Trick for modular division ( (x1 * x2 .... xn) / b ) mod (m) - GeeksforGeeks

can you please specify what variable indicates.

Can you please include the derivation for the “Ans” formula. It will be extremely helpful

Your approach is wrong if you take n>>k let’s say n=1000 k=5 then it will not work also you also have to take first k-1 numbers it will work fine if n=2 then no became k,k+1

Derivation for final formula Added.

Check out my answer . All the variables I used are easy to understand the solution.
Even I was stuck on it before I performed Modulo by separating into two brackets.

https://www.codechef.com/viewsolution/24790923

I edited the comment.

good explanation man