https://www.codechef.com/LRNDSA05/problems/BINXOR

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
((fact[n]*1LL*inv[r])%mod*inv[n-r])%mod;

// my incorrect solution
(fact[n]*1LL*(inv[r]*inv[n-r])%mod)%mod;


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

What’s wrong with my solution?