{
  "id": "linear-diophantine-equation",
  "title": "Linear Diophantine Equation",
  "lang": "en",
  "source_lang": "en",
  "summary": "A linear Diophantine equation is a linear equation with integer coefficients whose unknowns are required to take integer values.",
  "category": "mathematics",
  "subcategory": "algebra",
  "type": "concept",
  "aliases": [
    "Diophantine equation of degree one",
    "linear indeterminate equation"
  ],
  "generated_at": "2026-11-05",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/linear-diophantine-equation/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/linear-diophantine-equation/",
      "json": "https://aiwiki.page/zh/linear-diophantine-equation.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "A linear Diophantine equation is an equation of the form\n\n\\[a_1x_1+\\cdots+a_nx_n=b,\\]\n\nwhere the coefficients \\(a_1,\\ldots,a_n\\) and the constant \\(b\\) are integers, and integer values are sought for the unknowns \\(x_1,\\ldots,x_n\\). It is a degree-one case of a Diophantine equation and a basic subject of number theory. Unlike a linear equation over the real or rational numbers, its solvability depends on divisibility. A single nontrivial linear Diophantine equation has an integer solution exactly when the greatest common divisor of its coefficients divides its constant term."
    },
    {
      "heading": "Definition and scope",
      "text": "The word linear means that each unknown occurs only to the first power, with no products between unknowns. For example,\n\n\\[6x+10y=14\\]\n\nis linear, whereas \\(x^2+y^2=14\\) and \\(xy=14\\) are not.\n\nThe integer requirement is essential. An equation such as\n\n\\[6x+10y=7\\]\n\nhas solutions over the rational numbers and the real numbers, but none over the integers: its left-hand side is always even.\n\nUnless additional restrictions are stated, negative values and zero are allowed. Problems requiring nonnegative integer solutions, positive integer solutions, or solutions within specified bounds are more restrictive and need separate analysis.\n\nA collection of linear Diophantine equations forms an integer system of linear equations, commonly written \\(A\\mathbf{x}=\\mathbf{b}\\)."
    },
    {
      "heading": "Solvability criterion",
      "text": "Suppose the coefficients \\(a_1,\\ldots,a_n\\) are not all zero, and let\n\n\\[d=\\gcd(a_1,\\ldots,a_n)>0\\]\n\nbe their greatest common divisor. Then\n\n\\[a_1x_1+\\cdots+a_nx_n=b\\]\n\nhas an integer solution if and only if\n\n\\[d\\mid b.\\]\n\nNecessity\n\nBecause \\(d\\) divides every coefficient \\(a_i\\), it divides every integer linear combination\n\n\\[a_1x_1+\\cdots+a_nx_n.\\]\n\nConsequently, an integer solution can exist only if \\(d\\) divides \\(b\\).\n\nSufficiency\n\nBézout’s identity states that there are integers \\(u_1,\\ldots,u_n\\) satisfying\n\n\\[a_1u_1+\\cdots+a_nu_n=d.\\]\n\nIf \\(b=kd\\) for an integer \\(k\\), multiplying this identity by \\(k\\) gives a solution:\n\n\\[x_i=ku_i,\\qquad i=1,\\ldots,n.\\]\n\nEquivalently, the integers representable by integer linear combinations of the coefficients are precisely the multiples of their greatest common divisor.\n\nIf all coefficients are zero, the equation reduces to \\(0=b\\). It then has every integer tuple as a solution when \\(b=0\\), and no solution when \\(b\\ne0\\)."
    },
    {
      "heading": "Equations in two unknowns",
      "text": "The classical two-variable equation is\n\n\\[ax+by=c.\\]\n\nAssume \\(a\\) and \\(b\\) are not both zero, and write\n\n\\[d=\\gcd(a,b)>0.\\]\n\nIf \\(d\\nmid c\\), there are no integer solutions. If \\(d\\mid c\\) and \\((x_0,y_0)\\) is one solution, then all integer solutions are\n\n\\[\\boxed{ x=x_0+\\frac{b}{d}t,\\qquad y=y_0-\\frac{a}{d}t,\\qquad t\\in\\mathbb Z. }\\]\n\nThus one particular solution determines the entire solution set.\n\nWhy the parameterization is complete\n\nSuppose first that \\(a\\) and \\(b\\) are both nonzero. Subtracting the equation for \\((x_0,y_0)\\) from that for another solution \\((x,y)\\) gives\n\n\\[\\frac{a}{d}(x-x_0) =-\\frac{b}{d}(y-y_0).\\]\n\nThe integers \\(a/d\\) and \\(b/d\\) are relatively prime. Therefore \\(b/d\\) divides \\(x-x_0\\), so\n\n\\[x-x_0=\\frac{b}{d}t\\]\n\nfor an integer \\(t\\). Substitution gives the stated formula for \\(y-y_0\\). Conversely, direct substitution shows that every integer \\(t\\) produces a solution.\n\nIf one coefficient is zero, the same parameterization remains valid: the unknown with nonzero coefficient is fixed, while the other is an arbitrary integer.\n\nExample\n\nConsider\n\n\\[14x+21y=35.\\]\n\nSince \\(\\gcd(14,21)=7\\) and \\(7\\mid35\\), solutions exist. The identity\n\n\\[14(-1)+21(1)=7\\]\n\ngives the particular solution \\((-5,5)\\) after multiplication by \\(5\\). Hence all solutions are\n\n\\[x=-5+3t,\\qquad y=5-2t,\\qquad t\\in\\mathbb Z.\\]\n\nFor instance, \\(t=2\\) gives \\((x,y)=(1,1)\\), while \\(t=1\\) gives \\((-2,3)\\). In contrast,\n\n\\[14x+21y=36\\]\n\nhas no integer solution because \\(7\\) does not divide \\(36\\)."
    },
    {
      "heading": "Computing solutions",
      "text": "The standard method uses the extended Euclidean algorithm. In addition to calculating \\(d=\\gcd(a,b)\\), it finds integers \\(u,v\\) such that\n\n\\[au+bv=d.\\]\n\nA solution procedure is:\n\n- Compute \\(d,u,v\\).\n- Test whether \\(d\\mid c\\).\n- If so, take\n\n\\[x_0=u\\frac{c}{d},\\qquad y_0=v\\frac{c}{d}.\\]\n- Introduce an arbitrary integer parameter using the general solution formula.\n\nThe Euclidean algorithm uses a number of division steps logarithmic in the magnitude of the smaller nonzero input. Full bit complexity also depends on the cost of arithmetic on the integers involved.\n\nFor more than two coefficients, the algorithm can be applied repeatedly:\n\n\\[\\gcd(a_1,a_2,a_3) =\\gcd\\bigl(\\gcd(a_1,a_2),a_3\\bigr).\\]\n\nKeeping track of the corresponding identities produces a particular solution whenever the divisibility criterion is satisfied."
    },
    {
      "heading": "Connection with congruences",
      "text": "The equation\n\n\\[ax+by=c\\]\n\nimplies\n\n\\[ax\\equiv c\\pmod{|b|}\\]\n\nwhen \\(b\\ne0\\). Conversely, any integer \\(x\\) satisfying this congruence yields an integer\n\n\\[y=\\frac{c-ax}{b}.\\]\n\nThus solving a two-variable linear Diophantine equation is closely related to solving a linear congruence in modular arithmetic.\n\nFor a positive modulus \\(m\\), the congruence\n\n\\[ax\\equiv c\\pmod m\\]\n\nis solvable exactly when \\(\\gcd(a,m)\\mid c\\). If solvable, it has exactly \\(\\gcd(a,m)\\) distinct solution classes modulo \\(m\\).\n\nIn particular, when \\(\\gcd(a,m)=1\\), Bézout’s identity supplies a multiplicative inverse of \\(a\\) modulo \\(m\\). This connection also underlies constructive methods for the Chinese remainder theorem."
    },
    {
      "heading": "Nonnegative and bounded solutions",
      "text": "Integer solvability does not guarantee nonnegative integer solvability. For example,\n\n\\[2x+3y=1\\]\n\nsatisfies the greatest-common-divisor criterion and has the solution \\((-1,1)\\), but it has no solution with both \\(x\\ge0\\) and \\(y\\ge0\\).\n\nWhen \\(a,b>0\\), inserting the two-variable parameterization into the nonnegativity constraints gives\n\n\\[x_0+\\frac{b}{d}t\\ge0,\\qquad y_0-\\frac{a}{d}t\\ge0.\\]\n\nConsequently,\n\n\\[\\left\\lceil-\\frac{dx_0}{b}\\right\\rceil \\le t\\le \\left\\lfloor\\frac{dy_0}{a}\\right\\rfloor.\\]\n\nIf these endpoints are \\(L\\) and \\(U\\), the number of nonnegative solutions is\n\n\\[\\max(0,U-L+1).\\]\n\nFor the example \\(14x+21y=35\\), the parameterization gives\n\n\\[t\\ge2,\\qquad t\\le2.\\]\n\nIts only nonnegative solution is therefore \\((1,1)\\). Additional upper or lower bounds on the unknowns can be handled by intersecting the resulting intervals for \\(t\\).\n\nA related problem is the Frobenius coin problem. For relatively prime positive integers \\(a,b>1\\), the largest integer that cannot be expressed as\n\n\\[ax+by,\\qquad x,y\\ge0,\\]\n\nis\n\n\\[ab-a-b.\\]\n\nThis result concerns nonnegative solutions; unrestricted integer solutions exist for every right-hand side when \\(\\gcd(a,b)=1\\)."
    },
    {
      "heading": "Several unknowns and lattice structure",
      "text": "For a single equation in \\(n\\) unknowns with at least one nonzero coefficient, the solution set, when nonempty, has the form\n\n\\[\\mathbf{x}_0+L,\\]\n\nwhere\n\n\\[L=\\left\\{\\mathbf{z}\\in\\mathbb Z^n: a_1z_1+\\cdots+a_nz_n=0\\right\\}.\\]\n\nThe set \\(L\\) is a lattice of rank \\(n-1\\). It has an integer basis \\(\\mathbf{v}_1,\\ldots,\\mathbf{v}_{n-1}\\), giving\n\n\\[\\mathbf{x} =\\mathbf{x}_0+t_1\\mathbf{v}_1+\\cdots+t_{n-1}\\mathbf{v}_{n-1}, \\qquad t_i\\in\\mathbb Z.\\]\n\nGeometrically, the equation defines a hyperplane in real coordinate space, and the Diophantine problem asks which integer-coordinate points lie on it. For \\(n\\ge2\\), every solvable nontrivial equation has infinitely many unrestricted integer solutions. Nonnegativity or boundedness constraints may reduce this set to finitely many points or eliminate it entirely.\n\nThe integer lattice basis is not interchangeable with an arbitrary rational basis of the real homogeneous solution space. Simply clearing denominators in a rational basis can produce vectors that generate only a proper sublattice of the integer solutions."
    },
    {
      "heading": "Systems and Smith normal form",
      "text": "For a system\n\n\\[A\\mathbf{x}=\\mathbf{b},\\]\n\nwhere \\(A\\) is an integer matrix, ordinary Gaussian elimination determines rational consistency but does not by itself characterize integer solvability.\n\nA systematic integer method uses Smith normal form. There are unimodular integer matrices \\(U,V\\)—integer matrices with determinant \\(1\\) or \\(-1\\)—such that\n\n\\[UAV=D,\\]\n\nwhere \\(D\\) is diagonal in the rectangular-matrix sense. Its nonzero diagonal entries satisfy\n\n\\[d_1\\mid d_2\\mid\\cdots\\mid d_r,\\]\n\nwith \\(r\\) the rank of \\(A\\).\n\nSetting\n\n\\[\\mathbf{x}=V\\mathbf{y},\\qquad \\mathbf{c}=U\\mathbf{b}\\]\n\ntransforms the system into\n\n\\[D\\mathbf{y}=\\mathbf{c}.\\]\n\nBecause \\(U\\) and \\(V\\) preserve integer coordinates bijectively, integer solvability is equivalent to\n\n\\[d_i\\mid c_i\\quad(1\\le i\\le r),\\]\n\ntogether with\n\n\\[c_i=0\\quad(i>r)\\]\n\nfor the remaining rows. The unconstrained coordinates of \\(\\mathbf{y}\\) parameterize all solutions. For a single equation, the sole nonzero Smith invariant is the greatest common divisor of its coefficients."
    },
    {
      "heading": "Applications and computational limits",
      "text": "Linear Diophantine equations model exact balance conditions involving indivisible quantities: numbers of items in packages, denominations in payment problems, integer counts in resource allocation, and periodicity constraints.\n\nThey also form the equality constraints of many integer programming problems. Without inequalities or sign restrictions, solvability and parameterization admit systematic methods based on greatest common divisors and integer matrix reduction. Adding nonnegativity, capacity limits, or an optimization objective changes the problem substantially. Although the two-variable case remains directly manageable through its integer parameter, general integer programming can be computationally difficult.\n\nThe important distinction is between finding integer solutions to linear equalities and finding solutions that also belong to a prescribed feasible set. The greatest-common-divisor criterion completely resolves the former for one equation, but not the latter."
    }
  ],
  "links": [
    "integer",
    "diophantine-equation",
    "number-theory",
    "rational-number",
    "real-number",
    "system-of-linear-equations",
    "greatest-common-divisor",
    "linear-combination",
    "bezouts-identity",
    "euclidean-algorithm",
    "modular-arithmetic",
    "chinese-remainder-theorem",
    "hyperplane",
    "matrix",
    "gaussian-elimination",
    "smith-normal-form",
    "matrix-rank",
    "integer-programming",
    "feasible-set"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}