I have used fermat’s little theorem to solve this problem but still getting wrong answer on some testcase. Please suggest some way to rectify it.
Code: https://ide.codingblocks.com/s/94157
WA in Virat and nCr
it is about calculating factorials under modula,
than taking inverses
nCr= N!*inverse(R!)*inverse(N-R!)
That;s what I’m doing I guess.
I first calculated factorials of r! and (n-r)! using
ll temp1=fac[r];
ll temp2=fac[n-r];
and then put power (p-2) over it.
What changes should I make?
multiply in steps;
meaning
ans=(abc)%mod;
so you do it like
ans=(ab)%mod;
and then–
ans=(ansc)%mod;
to avoid interger overflows
1 Like
i have made the modifications -
check it
1 Like
Thanks
Got accepted
Can you mark this issue resolved from your side as I’m not able to mark it down because of some technical fault.
yeah sure…