-1

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.

nbrooks
  • 18,126
  • 5
  • 54
  • 66
Andrew Koroluk
  • 611
  • 6
  • 19

3 Answers3

5

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.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
2

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.

kaosjester
  • 121
  • 4
  • 1
    Indeed. If `b` and `m` are relatively prime, there is a `c` such that `b*c mod m = 1`. Then `(a/b) mod m == (a/b)*(c*b) mod m == (a*c) mod m == (a mod m) * c mod m` and similarly for `b mod m`. – Daniel Fischer Jan 02 '12 at 15:07
0

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..

David
  • 72,686
  • 18
  • 132
  • 173
Kartik
  • 11