Method 1:
Think about how you usually calculate 500! / (20! * 20! * 20! * ...) 500! / (20! * 20! * 20! * ...) .
Do not multiply everything and do not divide at the end. Make your divisions in the middle. Then combine this with the module reduction from the previous question.
Method 2:
Prime factorize 500! and 20! . Then subtract the prime factors of 20! * 20! * 20! 20! * 20! * 20! (or how many of them you have) of 500! simple factors 500! .
Then rearrange the number by multiplying the remaining factors together. (at the same time taking the module along the path to keep the number from large)
Method 3:
If 1000000007 (or any module) is simple, you can do the division using the modular inverse .
Calculate 20! mod 1000000007 20! mod 1000000007 . Then calculate it with the modular inverse and multiply by 500! mod 1000000007 500! mod 1000000007 .
source share