Search code examples
mathmodular

Modular arithmetic calculation


Is there any way to calculate (a mod c)*(b mod c)?

Knowing only:

  • a*b
  • c
  • d
  • ((a mod c)*(b mod c)) mod c
  • (a mod d)*(b mod d)

Solution

  • No, it's impossible.

    Here's a counterexample:

    ab = 1225 = (5)(5)(7)(7)
    c = 3
    d = 5000
    ((a mod c)(b mod c)) mod c = 1
    (a mod d)(b mod d) = 1225
    

    If a=25 and b=49, then (a mod c)(b mod c)=(1)(1)=1

    If a=35 and b=35, then (a mod c)(b mod c)=(2)(2)=4