Solving a Linear Diophantine Equation in Two Variables by the Euclidean Algorithm

Requires a Wolfram Notebook System

Interact on desktop, mobile and cloud with the free Wolfram CDF Player or other Wolfram Language products.

Requires a Wolfram Notebook System

Edit on desktop, mobile and cloud with any Wolfram Language product.

This Demonstration shows the solutions of Diophantine equations of the form , and using the Euclidean algorithm.

Contributed by: Izidor Hafner (September 2016)
Open content licensed under CC BY-NC-SA



A linear Diophantine equation can have either no solutions, exactly one solution or infinitely many solutions.

Let and be nonzero integers, and let . The equation always has a solution in integers, and this solution can be found by the Euclidean algorithm. Then every solution to the equation can be obtained by substituting for the integer in the formula

[1, p. 37].

If , then we have the equation , which is . It has one solution , and the general solution is .

The homogeneous equation has the general solution .

The Diophantine equation has no solution if if not divisible by . If , then the equation has the general solution , so that .

[1]. J. H. Silverman, A Friendly Introduction to Number Theory, Upper Saddle River, NJ: Prentice Hall, 1997.

Feedback (field required)
Email (field required) Name
Occupation Organization
Note: Your message & contact information may be shared with the author of any specific Demonstration for which you give feedback.