Hey, I was doing a problem recently, and after quite a mathematical struggle I reached the answer of the problem to be in form of (nCr % MOD) where nCr = n! / (n-r)! and MOD is in int range
Now the thing is my n can be as big as 2*10^6. I have seen ppl do this in O(1) time by precomputing all values of n!
But how is it possible to avoid overflow, and is there a general technique to find this (apart from multiplying numbers from 1 through n, 1 through r)
Can someone elaborate please, or give some link of a nice reference.
I can provide the problem link as well, but I think that's irrelevant, I just want a general approach towards such problem. Sorry for another post, I couldn't really find something specific like this in previous posts.
created
last reply
- 10
replies
- 1.8k
views
- 3
users
- 1
like
- 4
links