This is my solution

Line number 34 return ((fact[n]*1LL*inv[r])%mod*inv[n-r])%mod; is being copied from other’s solution.

  (nCr)%P is equivalent to (n! /(r! * (n-r)!))%P                        
// according to modular mathematics 
  => (n!%P * modInverseOf(r! * (n-r)!)%P)%

// we are doing the same in the solution
// correct solution

// my incorrect solution

// inv[i] contains the mod inverse of i
// fact[n] contains n!%P

What’s wrong with my solution?