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 an equation of a straight line of form $Ax + By = C$. where $A,B,C$ are integers. How could we check if this passes through any lattice point or not?

Please suggest me a suitable algorithm.

share|cite|improve this question
What is the lattice? – Fabian Apr 10 '11 at 19:13
Assuming you mean the integer lattice in $\mathbb{R}^2$, it might be instructive to consider Euclid's Algorithm, since there are always integer solutions to the equation $Ax+By=GCD(A,B)$. So if $GCD(A,B)\vert C$ then you definitely have integer solutions. I'm not sure about the converse, i.e. if GCD isn't a factor. – Jon Beardsley Apr 10 '11 at 19:19
i assume $\mathbb{Z}^2$. $Ax+By=C$ has solutions iff $(A,B)|C$ ($C$ would have to be in the ideal generated by $A,B$) – yoyo Apr 10 '11 at 19:19
@JBeardz Your argument is an if and only if statement. – Adrián Barquero Apr 10 '11 at 19:22
up vote 3 down vote accepted

Assuming you mean the lattice of integers, that is equivalent to checking if the equation has integer solutions.

Assume that $k\times GCD(A,B)=C$. Then by Euclid's algorithm, there are $X,Y$ such that $AX+BY=GCD(A,B)$, so $AkX+BkY=C$, where $kX$ and $kY$ must be integers.

On the other hand, assume $Ax+By=C$ has a solution. Then $GCD(A,B)\left(\frac{A}{GCD(A,B)}X+\frac{B}{GCD(A,B)}Y\right)=C$ so $GCD(A,B)$ divides $C$.

share|cite|improve this answer

I assume the lattice you are using is $\mathbb{Z}^2$, consisting of all integer pairs $(x,y)$. What you have is an example of a linear diophantine equation, meaning that you are looking for integer pairs $(x,y)$ satisfying this equation. The key here is to see whether or not $C$ is divisible by $gcd(A,B)$. If so, there are infinitely many solutions (this is known as Bezout's identity).

share|cite|improve this answer

Your Answer


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