If I want 1/i for 1<=i<=5000000, i.e. inv[i]
inv[1] = 1;
for (int i=2; i<p; ++i)
inv[i] = (p - (p/i) * inv[p%i] % p) % p;
I used this but it times out. So I wanted a way for this.
Besides that, if I use fact[i-1]*invfact[i] : would that solve? It is not giving me correct answer so plz tell me what is wrong over here?