This program is a C++ implementation of a solver for linear Diophantine equations.
Finding all possible values of
This is done with the help of the following functions:
-
extendedGCD(a, b)
computes the GCD ofa
andb
using the extended Euclidean algorithm. It additionally returns coefficientsx
andy
such that$a \cdot x + b \cdot y = \text{GCD}(a, b)$ . -
inverse(a, n)
computes the modular inverse ofa
modulon
using extended GCD algorithm to verify its existence. -
linsolve(a, b, n)
solves the linear congruence$a \cdot x \equiv b \ (\text{mod} \ n)$ ; if solutions exist, it computes and prints all possible solutions modulo$n$ .
All arithmetic has been simplified to assume values within the range of standard C++ long long
but can be easily modified to handle larger integers using the GMP Arithmetic Library.