Here is the link — http://codeforces.net/problemset/problem/559/C This is similar to this — https://www.codechef.com/CDCRF15R/problems/CWAYS/
In the solutions, I can see inverse factorial being calculated as
inv(n) = pow(n,mod-2)
I don't get where the mod-2 value comes from. Can someone please explain?