Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Given $x, y, r \in \mathbb{Z}$, how can you tell whether there exist two integers $a$ and $b$ such that $ax + by = r$?

That is, how do you determine whether an integral linear combination exists for $x$, $y$, and $r$?

share|cite|improve this question
Extended Euclidean algorithm? – Ganesh Oct 21 '12 at 2:26
up vote 2 down vote accepted

Consider $d = \gcd(x, y)$.

$$\textrm{Then} \; \frac{ax + by}{d} =\frac{r}{d}, \frac{ax + by}{d} \in \mathbb{Z}$$

If $d$ does not divide $r$, there exist no possible $a, b \in \mathbb{Z}$. If $d$ divides $r$, the solution can be found by the Extended Euclidean Algorithm. Thanks to Ganesh for pointing me in the right direction.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.