I have often encountered problems(in gym) which reduce to finding C(n,r) % p , where p is not necessarily prime . Also n and r are both large . Essentialy they demand for the use of Lucas and Chinese Remainder Theorem.
For constraints let`s take this problem .
This link does help a lot but I am still confused , especially in the part which asks to use C.R.Theorem . How to apply CRT?
Also what if p is not a square free number ?
Along with explaination , a link to code would be extremely helpful.