for calculating the value of choosing r items from n items where q are of same kind, and we should take %m , i used the following relation
(nPr/q!) %m
where m is prime
For calculating this
i calculated
n!
n!%m
then, i calculated
(n-r)!
and multiplied it with q!, i.etemp = (n-r)!*q!
;Then i mulitplied
modular mulitplicative inverse
of temp with n! and took mod of resultbut am not getting the correct answer..E.g if n= 3 ; r = 2; q = 2 then the expected result is
(3P2/2!)%1000000007 = 3
but am getting250000004
..I can't understand my mistake here..Thanks.