Module 4 : Modular Arithmetic

Lecture 1 : Solving modular linear equations

Proof: We have to show axi b mod n i ∈ (0 .. d -1) . Since d = gcd( a , n ) , d | a . Hence an integer k = a / d . From the given condition the following must hold:


axi a ( x0 + i ( n / d )) mod n ≡ ( ax0+ ai ( n / d )) mod n ≡ ( ax0 + kin ) mod n ax0 mod n b mod n.
So xi is a solution to the given equation. Thus we conclude there are d distinct solutions to the given equation.

The following procedure computes all solutions of the modular linear equation ax ≡ b mod n .

MODULAR-LINEAR-EQUATION-SOLVER ( a , b , n )

1.  ( d , x ' , y ' ) ← EXTENDED-EUCLID( a , n )
2.  if d | b
3.                  then x0
x ' ( b / d ) mod n
4.                           for i = 0 to d -1
5.                             do print ( x0 + i ( n / d )) mod n

6.       else print “No Solution.”

Exercise: Find all solutions to the equation 35 x ≡ 10 (mod 50)

Solution: Here a = 35, b = 10 and n = 50. We know gcd(35, 50) = 5. Thus there are 5 solutions to the given equation.

Since 3 x 35 + (-2) x 50 = 5 we have x' = 3. Thus x0 = x' ( b / d ) mod n = 3 x (10/5) mod 50 =

6. Other solutions are xi = x0 + i ( n / d ) [ i = 1, 2, …, 4 ] i.e., x1 = 16, x2 = 26, x3 = 36, x4 = 46.

Corollary 2: For any n > 1 if gcd( a, n ) =1 then the equation ax b mod n has exactly one solution.

Corollary 3: For any n > 1 if gcd( a, n ) =1 then the equation ax ≡ 1 mod n has exactly an unique solution, i.e., a -1 ∈ Z n*.

Reference:

1. Introduction to Algorithms , Second Edition, T. H. Cormen, C. E. Leiserson, R. Rivest and C. Stein, Prentice Hall India .

2. Introduction to Analytic Number Theory , T. M. Apostol, Springer International .