Write a FORTRAN program to solve linear congruence of the ax = b (mod m).
SOLUTION :
Two integers are said to be congruent modulo an integer m if
their difference is divisible by m. Thus a ≡ b (mod a) means
(a−b)/m is an integer. For example, 3 ≡ 8 (mod 5) since [(3 – 8) /
5] = (−5/5) = −1 (an integer).
Congruences are similar to equations and linear congruences are
similar to linear equations. The linear congruence
ax ≡ b (mod m)
has a solution if and only if (a, m) (the greatest common divider
of a and m) divides b, i.e., (a, m)/b. Furthermore if x₀ is such a
solution, then
x ≡ x₀ (mod m/(a, m)) is also a solution.
For example, solve the linear congruence
8x ≡ 4 (mod 6). (1)
By definition, (1) means
(8x – 4) / 6 = 3 integer
When x = 2, 8x − 4 = 12, and six divides twelve. Now, (8,6) =
2.
Hence any x satisfying
x ≡ 2 (mod 6/(8,6)), or ax − b = rm or ax − rm = b....(2)
Equation (2) is a linear Diophantine equation and is solvable for r
and x if and only if (a, m) divides b.
The strategy in the presented computer program is as follows:
1) Read in values of a, b and m (< 10000).
2) Call a subroutine that solves the linear Diophantine equation
described above.
3) Return to main program.
The program terminates when the value of M read in is less than, or
equal to 0 5 BEAD (5,10) IA,M, IB
10 FORMAT (3I4)
IF (M.LE.O) GO TO 99
20 CALL GLDE(IA,M,IB,M1,N1,NA,INDEX)
IF (INDEX) 30,30,22
22 WRITE (6,25)
25 FORMAT (1HO,45HNO VALUE OF X SATISFIES
1 THE LINEAR CONGRUENCE)
GO TO 40
30 WRITE (6,35) IX
35 FORMAT (1HO.3HX =, I6, 32H SATISFIES THE LINEAR
CONGRUENCE)
40 WRITE (6,44), IA,IB,M
44 FORMAT (1H , I6, 5HX (=),I16, 4H(MOD,I6,1H))
GO TO 5
99 STOP
END
SUBROUTINE GLDE(M,N,K,M1,N1,NA,INDEX)
C THIS SUBROUTINE RECEIVES INTEGERS FROM
C MAIN PROGRAM. FIRST, ANOTHER SUBROUTINE LDE IS CALLED, THAT FINDS
THE GCD NA OF (N,M),
C AND DETERMINES VALUES M1 AND N1 THAT SATISFY THE LINEAD
C DIOPHANTINE EQUATION M*M1 + N * N1 = K.
C THE VALUE OF M1 RETURNED HAS THE LEAST
C POSSIBLE ABSOLUTE VALUE. INDEX IS SET
C TO 0 IF A SOLUTION EXISTS, TO / IF NOT,
C AND TO −1 IF THE VALUE RECEIVED FOR
C K IS, SAY, 30000. USE K = 30000 IF A
C SOLUTION TO THE EQUATION
C M*M1 + N*N1 = NA (GCD OF M AND N)
C IS DESIRED. NOTE: THE NUMBER 30000
C IS SOMEWHAT ARBITRARILY CHOSEN. IT IS
C ASSUMED THAT ONE WOULD NEVER WISH
C TO SOLVE THE EQUATION MX + NY = 30000.
CALL LDE (M,N,M1,N1,NA)
IF (K − 30000) 22,21,22
21 INDEX = −1
K = NA
GO TO 27
22 MULT = K/NA
IF (K − MULT * NA) 23,25,23
23 INDEX = 1
RETURN
25 Ml = M1 * MULT
N1 = N1 * MULT
27 MTEST = M1
ND = N/NA
MD = M/NA
MX = M1
30 MX = MX + ND
IF (IABS(MX) − LABS (M1)) 35,40,40
35 M1 = MX
N1 = N1 − MD
GO TO 30
40 IF (MTEST – M1) 65,45,65
45 MX = M1
50 MX = MX − ND
IF (IABS(MX) − IABS(M1)) 55,65,65
55 M1 = MX
N1 = N1 + MD
GO TO 50
65 INDEX = 0
RETURN
END
SUBROUTINE LDE(M,N,M1,N1,NA)
MO = 1
NO = 0
M1 = 0
N1 = 1
MA = IABS(M)
NA = IABS(N)
MS = M/MA
NS = N/NA
25 IQUOT = MA/NA
IREM = MA − NA * IQUOT
IF (IREM) 35,35,30
30 M2 = MO − IQUOT * M1
M2= NO − IQUOT * N1
MO = M1
NO= N1
M1 = M2
N1 = N2
MA = NA
NA = IREM
GO TO 25
35 M1 = MS * M1
N1 = NS * N1
RETURN
END
Write a FORTRAN program to solve linear congruence of the ax = b (mod m).
(3) Solve the following linear congruence: 271 = 12 mod 39. (4) Solve the following set of simultaneous linear congruences: 3x = 6 mod 11, x = 5 mod 7 and 2x = 3 mod 15.
1. Solve each linear congruence for all integers x so that 0 sx <m a) 11x 8 (mod 57) b) 14x 3 (mod 231)
Problem 2. Solve the congruence equation x( 12 mod 143
Problem 2. Solve the congruence equation x( 12 mod 143
the integer x such that 5 3 (mod 7) 57 (mod 61) e linear congruence 31
Solve the congruence: 4x^2 + 8x ≡ 5 (mod 11)
Prove Congruence Property 3
C3 If a=b (mod m) and c < 1, then ac = bc (mod mc)
Write the system of linear equations in the form Ax = b and solve this matrix equation for x. = 9 -X1 + X2 -2x1 + x2 = 0 (No Response) (No Response) X1 1- [:)] (No Response) (No Response) X2 (No Response) X1 X2 (No Response)
Write the system of linear equations in the form Ax = b and solve this matrix equation for x. x1 – 2x2 + 3x3 = 24 -X1 + 3x2 - x3 = -11 2x1 – 5x2 + 5x3 = 42 X1 x2 = X3 ] 24 -11 42 [ x
13. Solve the congruence: 341x = 2941 (mod 9). v Hint First reduce each number modulo 9, which can be done by adding up the digits of the numbers.
Solve the congruence equation arb(mod 13). b-7 d 1. 11. d-9 1, b 8, d9 4, b6 d a2, b6 dm4 5, b8d Soue the congruente eguation axblmod 13) d a a Ti a V) a 4 v) a P vi a- s
Solve the congruence equation arb(mod 13). b-7 d 1. 11. d-9 1, b 8, d9 4, b6 d a2, b6 dm4 5, b8d
Soue the congruente eguation axblmod 13) d a a Ti a V) a 4...