Does a/b mod m = (a mod m)/(b mod m)
?
I am trying to find nCr mod m for very large numbers. If a/b mod m = (a mod m)/(b mod m)
then think I will have solved my problem.
It is for Project Euler. I am using the nCr formula using factorials.
Does a/b mod m = (a mod m)/(b mod m)
?
I am trying to find nCr mod m for very large numbers. If a/b mod m = (a mod m)/(b mod m)
then think I will have solved my problem.
It is for Project Euler. I am using the nCr formula using factorials.
No.
If you have a=8, b=2, m=2
then you have a/b mod m = 8/2 mod 2 = 4 mod 2 = 0
and (a mod m)/(b mod m) = (8 mod 2)/(2 mod 2) = 0/0 = NaN
NaN
is not equal to 0
.
This identity does not hold. Here is a counter-example:
Let a = 21, b = 7, m = 7.
Then (21/7) = 3 and 3 mod 7 = 3
Alternately, 21 mod 7 = 0 and 7 mod 7 = 0.
But 0 / 0 is undefined (and certainly not 3).
Thus your identity does not hold. However, I am almost certain that it will hold if m and b are relatively prime.
You can use the following link to evaluate (a/b)mod m..... http://mathworld.wolfram.com/Congruence.html
The answer for evaluating is given at the end..