You are viewing a single comment's thread. Return to all comments →
You need to calculate factorials using method posted in first reply.
a = 499! (mod p)
b = 500! (mod p)
where, 0 <= a, b < p
Now problem reduces to
1/(a*b) = (a*b)^-1 (mod p)
= c^-1 (mod p)
= c^(p-2) (mod p)
where, c = (a*b)%p
Now use fast exponential method, posted in last reply, to calculate higher power.
thanks sir...ur explanation helped to pass all test cases in 1st attempt....i always wanted to learn modular arithmetic on large numbers :)