For ax% b = c, where a, b, and c are known, how to find a suitable x?

From what I can say, this is not a multiplicative inverse modulo (which I continue to search with Google search queries), since x is unknown. b and a are coprime, and% is the module operator used in most programming languages. Using a for loop to find matches can take up to 4 billion iterations to find the corresponding x value. I know that for x there is more than one value of x that solves this equation ... I need the smallest value greater than 0.

I know that this can be rewritten as ax - by = c, where both x and y are unknown, but I do not know how to solve this equation to match x, where x and y are integers. I continue to work in the Euclid solution for gcd (m, n) = 1 in connection with this problem, but although I can implement this algorithm, I do not know how to use the results to solve my problem.

Although this seems to be a mathematical issue, it is in the area of β€‹β€‹β€œcomputer” mathematical and algorithms instead of the theoretical ones that I continue to search with a search on Google. I hope for a simple algorithm, equation or built-in math call, if possible - the sample code will be awesome.

Thanks.

+4
source share

All Articles