{"id":66848,"date":"2026-10-15T09:20:24","date_gmt":"2026-10-15T06:20:24","guid":{"rendered":"https:\/\/wpcalc.com\/en\/?p=66848"},"modified":"2026-10-15T09:20:24","modified_gmt":"2026-10-15T06:20:24","slug":"linear-diophantine-equation-calculator","status":"publish","type":"post","link":"https:\/\/wpcalc.com\/en\/mathematics\/linear-diophantine-equation-calculator\/","title":{"rendered":"Linear Diophantine Equation Calculator"},"content":{"rendered":"<section class=\"not-prose calculator-box\" aria-labelledby=\"calculator-title\"><div class=\"flex items-baseline sm:items-center justify-between gap-2 sm:gap-3\"><div class=\"flex flex-col sm:flex-row sm:items-center gap-2\"><span class=\"icon icon-calculator text-primary-700! text-base! dark:text-primary-300!\" aria-hidden=\"true\"><\/span><h2 id=\"calculator-title\" class=\"text-lg font-display font-bold\">Solve ax + by = c in Integers<\/h2><\/div><div class=\"calcdash-favorite group\">\n  <button type=\"button\" class=\"favorite\" id=\"favorite\" data-favorite-id=\"66848\" data-favorite-title=\"Linear Diophantine Equation\" data-favorite-url=\"https:\/\/wpcalc.com\/en\/mathematics\/linear-diophantine-equation-calculator\/\" data-favorite-excerpt=\"Solves the linear Diophantine equation ax + by = c in integers. Enter the coefficients a, b and c to check whether solutions exist, get one particular solution and the full family x = x\u2080 + (b\/g)t, y = y\u2080 \u2212 (a\/g)t.\" aria-label=\"Add to Favorites\" data-favorite-icon=\"icon icon-algebra\">\n    <span class=\"icon icon-shape-star-empty\" aria-hidden=\"true\"><\/span>\n  <\/button>\n  <div class=\"calcdash-favorite__tip\" aria-hidden=\"true\">\n   <span class=\"favorite-tooltip\" id=\"favorite-tooltip\"><\/span>\n  <\/div>\n  <span class=\"sr-only\" role=\"status\" id=\"favorite-status\"><\/span>\n<\/div><\/div><form action=\"https:\/\/wpcalc.com\/en\/mathematics\/linear-diophantine-equation-calculator\/\" method=\"POST\" class=\"calculator\" id=\"calculator-66848\" data-post=\"66848\"><fieldset class=\"fieldset-input is-1\"><legend class=\"sr-only\">Input Fields<\/legend><div class=\"field has-term\" id=\"input-1\"><label for=\"field-1\">Coefficient of x (a)<\/label><div class=\"term\">a<\/div>  <div class=\"absolute bottom-0 left-16 top-8 w-2 h-0.5 bg-blue-500\"><\/div><input type=\"number\" name=\"coefficient_of_x_a\" id=\"field-1\" placeholder=\"e.g. 12\" step=\"1\" value=\"12\"\/><\/div><div class=\"field has-term\" id=\"input-2\"><label for=\"field-2\">Coefficient of y (b)<\/label><div class=\"term\">b<\/div>  <div class=\"absolute bottom-0 left-16 top-8 w-2 h-0.5 bg-blue-500\"><\/div><input type=\"number\" name=\"coefficient_of_y_b\" id=\"field-2\" placeholder=\"e.g. 18\" step=\"1\" value=\"18\"\/><\/div><div class=\"field has-term\" id=\"input-3\"><label for=\"field-3\">Right-hand side (c)<\/label><div class=\"term\">c<\/div>  <div class=\"absolute bottom-0 left-16 top-8 w-2 h-0.5 bg-blue-500\"><\/div><input type=\"number\" name=\"righthand_side_c\" id=\"field-3\" placeholder=\"e.g. 30\" step=\"1\" value=\"30\"\/><\/div><\/fieldset><div class=\"buttons\"><button type=\"submit\" data-text=\"Re-Calculate\" id=\"calculate-button\" data-post=\"66848\">Calculate<\/button><button type=\"reset\">Reset<\/button><\/div><div class=\"field is-checkbox hidden!\" id=\"field-auto-calc\"><input type=\"checkbox\" id=\"auto-calc\"><label for=\"auto-calc\">Calculate automatically<\/label><small>If enabled, the result will update automatically when you change any value.<\/small><\/div><div class=\"fieldset-result is-hidden\" aria-labelledby=\"result-title\" aria-live=\"polite\" role=\"region\"> <h3 class=\"result-title bg-gradient-to-r from-primary-50 to-gray-50 dark:from-primary-900 dark:to-gray-800\" id=\"result-title\"><span class=\"icon icon-s-pulse\" aria-hidden=\"true\"><\/span> Diophantine Equation Results<\/h3><div class=\"result-box\"><div class=\"field-result is-column\" id=\"output-1\"><span class=\"field-title\"><span>Do integer solutions exist?<\/span><\/span><span class=\"field-value\" id=\"result-1\"><\/span><button type=\"button\" class=\"copy-result\" data-tooltip=\"Copy Result\" aria-label=\"Copy Result\"><span class=\"copy-icon icon icon-document-copy\" aria-hidden=\"true\"><\/span><\/button><\/div><div class=\"field-result is-column\" id=\"output-2\"><span class=\"field-title\"><span>One solution (x\u2080, y\u2080)<\/span><\/span><span class=\"field-value\" id=\"result-2\"><\/span><button type=\"button\" class=\"copy-result\" data-tooltip=\"Copy Result\" aria-label=\"Copy Result\"><span class=\"copy-icon icon icon-document-copy\" aria-hidden=\"true\"><\/span><\/button><\/div><div class=\"field-result is-column\" id=\"output-3\"><span class=\"field-title\"><span>General integer solution<\/span><\/span><span class=\"field-value\" id=\"result-3\"><\/span><button type=\"button\" class=\"copy-result\" data-tooltip=\"Copy Result\" aria-label=\"Copy Result\"><span class=\"copy-icon icon icon-document-copy\" aria-hidden=\"true\"><\/span><\/button><\/div><div class=\"field-result is-column\" id=\"output-4\"><span class=\"field-title\"><span>Solution steps<\/span><\/span><span class=\"field-value\" id=\"result-4\"><\/span><button type=\"button\" class=\"copy-result\" data-tooltip=\"Copy Result\" aria-label=\"Copy Result\"><span class=\"copy-icon icon icon-document-copy\" aria-hidden=\"true\"><\/span><\/button><\/div><\/div><div class=\"result-actions\"><button type=\"button\" class=\"copy-link\"><svg viewBox=\"0 0 20 20\" fill=\"currentColor\" aria-hidden=\"true\"><path d=\"M12.232 4.232a2.5 2.5 0 0 1 3.536 3.536l-1.225 1.224a.75.75 0 0 0 1.061 1.06l1.224-1.224a4 4 0 0 0-5.656-5.656l-3 3a4 4 0 0 0 .225 5.865.75.75 0 0 0 .977-1.138 2.5 2.5 0 0 1-.142-3.667l3-3Z\"\/><path d=\"M11.603 7.963a.75.75 0 0 0-.977 1.138 2.5 2.5 0 0 1 .142 3.667l-3 3a2.5 2.5 0 0 1-3.536-3.536l1.225-1.224a.75.75 0 0 0-1.061-1.06l-1.224 1.224a4 4 0 1 0 5.656 5.656l3-3a4 4 0 0 0-.225-5.865Z\"\/><\/svg><span class=\"copy-link__text\">Copy link to this calculation<\/span><\/button><span class=\"sr-only\" role=\"status\" id=\"copy-link-status\"><\/span><\/div><\/div><a href=\"#respond\" class=\"hidden transition-opacity duration-300 opacity-0 w-50 text-sm justify-center items-center gap-2 px-4 py-2 rounded bg-gray-200 text-gray-700 hover:bg-gray-300\" id=\"leave-comment\"><span class=\"icon icon-comments\" aria-hidden=\"true\"><\/span>Leave a Comment<\/a><\/form><\/section><section id=\"calc-reactions\" class=\"not-prose hidden my-12 bg-gradient-to-r from-primary-50 to-gray-50 border border-indigo-100 rounded-xl px-6 py-4 shadow-sm\" data-post=\"66848\" aria-live=\"polite\" aria-labelledby=\"calc-reactions-title\"><p id=\"calc-reactions-title\" class=\"text-sm text-gray-500 text-center mb-2\">How did this result make you feel?<\/p><div role=\"group\" aria-labelledby=\"calc-reactions-title\" class=\"grid grid-cols-3 sm:flex sm:flex-row sm:justify-around gap-4 sm:items-center sm:flex-wrap\"><button type=\"button\" aria-pressed=\"false\" class=\"reaction-btn flex flex-col items-center gap-1 text-sm text-gray-700 hover:text-primary-600 cursor-pointer transition-transform hover:scale-105\" data-reaction=\"like\"><span class=\"reaction-count\" data-reaction-count=\"like\">0<\/span><span class=\"reaction text-3xl\" aria-hidden=\"true\">\ud83d\ude00 <\/span><span class=\"reaction-description font-medium\">Like <\/span><\/button><button type=\"button\" aria-pressed=\"false\" class=\"reaction-btn flex flex-col items-center gap-1 text-sm text-gray-700 hover:text-primary-600 cursor-pointer transition-transform hover:scale-105\" data-reaction=\"helpful\"><span class=\"reaction-count\" data-reaction-count=\"helpful\">0<\/span><span class=\"reaction text-3xl\" aria-hidden=\"true\">\ud83d\udca1 <\/span><span class=\"reaction-description font-medium\">Helpful <\/span><\/button><button type=\"button\" aria-pressed=\"false\" class=\"reaction-btn flex flex-col items-center gap-1 text-sm text-gray-700 hover:text-primary-600 cursor-pointer transition-transform hover:scale-105\" data-reaction=\"confused\"><span class=\"reaction-count\" data-reaction-count=\"confused\">0<\/span><span class=\"reaction text-3xl\" aria-hidden=\"true\">\ud83d\ude15 <\/span><span class=\"reaction-description font-medium\">Confused <\/span><\/button><button type=\"button\" aria-pressed=\"false\" class=\"reaction-btn flex flex-col items-center gap-1 text-sm text-gray-700 hover:text-primary-600 cursor-pointer transition-transform hover:scale-105\" data-reaction=\"disappointed\"><span class=\"reaction-count\" data-reaction-count=\"disappointed\">0<\/span><span class=\"reaction text-3xl\" aria-hidden=\"true\">\ud83d\ude1e <\/span><span class=\"reaction-description font-medium\">Disappointed <\/span><\/button><button type=\"button\" aria-pressed=\"false\" class=\"reaction-btn flex flex-col items-center gap-1 text-sm text-gray-700 hover:text-primary-600 cursor-pointer transition-transform hover:scale-105\" data-reaction=\"inaccurate\"><span class=\"reaction-count\" data-reaction-count=\"inaccurate\">0<\/span><span class=\"reaction text-3xl\" aria-hidden=\"true\">\u274c <\/span><span class=\"reaction-description font-medium\">Inaccurate <\/span><\/button><\/div><div id=\"reaction-message\" class=\"hidden mt-8 rounded-md border border-primary-100 bg-white\/50 backdrop-blur-sm px-4 py-2 text-sm text-center shadow-sm\"><\/div><\/section><div class=\"calcdash-ad not-prose calcdash-ad--calc_result calcdash-ad--in-article\"><ins class=\"adsbygoogle\" style=\"display:block\" data-ad-client=\"ca-pub-1721569815777345\" data-ad-slot=\"6317458308\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\"><\/ins><script>(adsbygoogle = window.adsbygoogle || []).push({});<\/script><\/div>\n<style id=\"wpcoderpro-inline-1\">.formula-box {\r\n\tborder-bottom: none !important;\r\n}<\/style><section class=\"formula-box\" aria-labelledby=\"formula-title\">\r\n\t<div id=\"formula-title\" class=\"not-prose font-display mb-4\"><span class=\"icon icon-formula\" aria-hidden=\"true\"><\/span><h2>Linear Diophantine Equation Formula<\/h2><\/div>\r\n\t<figure class=\"not-prose formula\">\r\n\t\t<figcaption class=\"formula-title\">Formula<\/figcaption>\r\n\t\t<div class=\"text-base text-gray-800\" id=\"formula\">\n\\[ ax + by = c, \\qquad a, b, c \\in \\mathbb{Z} \\]\n\\[ g = \\gcd(a, b) \\]\n\\[ \\text{Integer solutions exist} \\iff g \\mid c \\]\n\\[ x = x_0 + \\frac{b}{g}\\,t, \\qquad y = y_0 - \\frac{a}{g}\\,t, \\qquad t \\in \\mathbb{Z} \\]\n<\/div>\r\n\t<\/figure>\r\n\t<\/p>\n<p><strong>Where:<\/strong><\/p>\n<ul>\n<li>\\(a\\), \\(b\\) \u2014 integer coefficients of \\(x\\) and \\(y\\)<\/li>\n<li>\\(c\\) \u2014 the integer right-hand side<\/li>\n<li>\\(g = \\gcd(a, b)\\) \u2014 the greatest common divisor of the coefficients<\/li>\n<li>\\((x_0, y_0)\\) \u2014 one particular solution, found from B\u00e9zout\u2019s identity \\(g = s\\,a + t\\,b\\) by multiplying by \\(c\/g\\)<\/li>\n<li>\\(t\\) \u2014 an arbitrary integer parameter that generates all solutions<\/li>\n<\/ul>\n<p>The equation has integer solutions exactly when \\(\\gcd(a,b)\\) divides \\(c\\). When it does, there are infinitely many of them: starting from one solution \\((x_0, y_0)\\), every other solution is obtained by adding \\(b\/g\\) to \\(x\\) and subtracting \\(a\/g\\) from \\(y\\) the same number of times \\(t\\).<\/p>\n<p>\r\n<\/section>\n<style id=\"wpcoderpro-inline-459\">.calculation-box {\r\n\tborder-bottom: none !important;\r\n}<\/style><section id=\"calculation\" class=\"calculation-box\" aria-labelledby=\"calculation-title\">\r\n\t<div id=\"calculation-title\" class=\"not-prose font-display\"><span class=\"icon icon-unordered-list\" aria-hidden=\"true\"><\/span><h2>Linear Diophantine Equation \u2013 Calculation Example<\/h2><\/div>\r\n\r\n<\/p>\n<p><strong>Example:<\/strong> solve \\(12x + 18y = 30\\) in integers (the calculator\u2019s default values).<\/p>\n<p>\\[ \\gcd(12, 18): \\quad 18 = 1 \\cdot 12 + 6, \\quad 12 = 2 \\cdot 6 + 0 \\implies \\gcd(12, 18) = 6 \\]<\/p>\n<p>\\[ 6 \\mid 30 \\implies \\text{solutions exist} \\]<\/p>\n<p>\\[ \\text{B\u00e9zout: } 6 = (-1) \\cdot 12 + 1 \\cdot 18, \\qquad \\frac{c}{g} = \\frac{30}{6} = 5 \\]<\/p>\n<p>\\[ x_0 = -1 \\cdot 5 = -5, \\qquad y_0 = 1 \\cdot 5 = 5 \\]<\/p>\n<p>\\[ 12 \\cdot (-5) + 18 \\cdot 5 = -60 + 90 = 30 \\;\\checkmark \\]<\/p>\n<p>Shifting \\(x_0\\) into the range \\(0 \\le x &lt; |b\/g| = 3\\) gives the equivalent particular solution \\((1, 1)\\), since \\(12 \\cdot 1 + 18 \\cdot 1 = 30\\).<\/p>\n<p><strong>Result:<\/strong> all integer solutions are \\(x = 1 + 3t\\), \\(y = 1 - 2t\\) for any integer \\(t\\); for example \\((1, 1)\\), \\((4, -1)\\), \\((-2, 3)\\).<\/p>\n<p>\n\r\n<\/section>\n<h2>How to use the calculator<\/h2>\n<ol>\n<li>Enter the integer coefficient of \\(x\\) in the field <strong>Coefficient of x (a)<\/strong>.<\/li>\n<li>Enter the integer coefficient of \\(y\\) in the field <strong>Coefficient of y (b)<\/strong>.<\/li>\n<li>Enter the right-hand side in the field <strong>Right-hand side (c)<\/strong>.<\/li>\n<li>Read the result blocks: <strong>Do integer solutions exist?<\/strong> tells you whether \\(\\gcd(a,b)\\) divides \\(c\\); <strong>One solution (x\u2080, y\u2080)<\/strong> gives a verified particular solution; <strong>General integer solution<\/strong> gives the complete family with the parameter \\(t\\); <strong>Solution steps<\/strong> shows the Euclidean algorithm, the B\u00e9zout coefficients and the reasoning.<\/li>\n<\/ol>\n<p>All three inputs must be whole numbers (positive, negative or zero). If you enter a non-integer value, the calculator will ask for a whole number, because Diophantine equations are by definition solved in integers only.<\/p>\n<h2>What is a linear Diophantine equation?<\/h2>\n<p>A Diophantine equation is an equation whose solutions are required to be integers. The linear Diophantine equation \\(ax + by = c\\) is the simplest kind: it asks for all integer pairs \\((x, y)\\) that satisfy it exactly, with no fractions or decimals allowed. Such equations appear naturally whenever quantities are indivisible \u2014 coins of fixed denominations, boxes of items, people, or tiles.<\/p>\n<p>The central fact is the solvability condition: \\(ax + by\\) is always a multiple of \\(\\gcd(a, b)\\), so \\(c\\) must be a multiple of \\(\\gcd(a, b)\\) as well. For example, \\(6x + 10y\\) is always even, so \\(6x + 10y = 7\\) has no integer solutions no matter how hard you search. When the condition holds, B\u00e9zout\u2019s identity guarantees at least one solution, which the extended Euclidean algorithm finds efficiently.<\/p>\n<p>Interpreting the result: if solutions exist, there are infinitely many of them along an arithmetic progression. The general solution \\(x = x_0 + (b\/g)t\\), \\(y = y_0 - (a\/g)t\\) lists them all \u2014 each step of the parameter \\(t\\) increases \\(x\\) by \\(b\/g\\) and decreases \\(y\\) by \\(a\/g\\), keeping \\(ax + by\\) constant. If you need solutions in a specific range (for example, non-negative ones), substitute a few values of \\(t\\) and keep those that fit.<\/p>\n<h2>Assumptions, limitations and tips<\/h2>\n<ul>\n<li><strong>Integers only.<\/strong> The coefficients must be whole numbers; the equation is not solved over the rationals or reals. Over the reals, \\(ax + by = c\\) always has solutions when \\(a\\) or \\(b\\) is non-zero \u2014 the integer restriction is what makes the problem interesting.<\/li>\n<li><strong>Size limits.<\/strong> The computation uses standard arithmetic, so keep the coefficients within the safe integer range (roughly up to 15 digits) to avoid precision issues.<\/li>\n<li><strong>Degenerate cases are handled.<\/strong> If \\(a = b = 0\\), the equation is either always true (\\(c = 0\\), every pair works) or never true. If exactly one coefficient is zero, the equation has a single variable and the calculator solves it directly.<\/li>\n<li><strong>Any particular solution is fine.<\/strong> The pair \\((x_0, y_0)\\) is not unique \u2014 the calculator shifts it to a compact form with \\(0 \\le x_0 &lt; |b\/g|\\), but every choice generates the same full solution set through the parameter \\(t\\).<\/li>\n<li><strong>Checking your answer.<\/strong> Always verify by substitution: compute \\(a x_0 + b y_0\\) and confirm it equals \\(c\\). The calculator does this check for you in the output.<\/li>\n<\/ul>\n<p>If your problem involves two linear equations at once instead of one, a system such as \\(ax + by = c\\), \\(dx + ey = f\\) is handled with the <a href=\"https:\/\/wpcalc.com\/en\/mathematics\/elimination-method\/\">elimination method<\/a> rather than with gcd divisibility. Diophantine reasoning also underpins topics like <a href=\"https:\/\/wpcalc.com\/en\/mathematics\/direct-variation\/\">direct variation<\/a>, where two integer-valued quantities grow in fixed proportion, and it is a classic tool in competition and number-theory problems.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Solves the linear Diophantine equation ax + by = c in integers. Enter the coefficients a, b and c to check whether solutions exist, get one particular solution and the full family x = x\u2080 + (b\/g)t, y = y\u2080 \u2212 (a\/g)t.<\/p>\n","protected":false},"author":3168,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[7],"tags":[11],"class_list":["post-66848","post","type-post","status-publish","format-standard","hentry","category-mathematics","tag-algebra"],"acf":[],"_links":{"self":[{"href":"https:\/\/wpcalc.com\/en\/wp-json\/wp\/v2\/posts\/66848","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpcalc.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpcalc.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpcalc.com\/en\/wp-json\/wp\/v2\/users\/3168"}],"replies":[{"embeddable":true,"href":"https:\/\/wpcalc.com\/en\/wp-json\/wp\/v2\/comments?post=66848"}],"version-history":[{"count":1,"href":"https:\/\/wpcalc.com\/en\/wp-json\/wp\/v2\/posts\/66848\/revisions"}],"predecessor-version":[{"id":67115,"href":"https:\/\/wpcalc.com\/en\/wp-json\/wp\/v2\/posts\/66848\/revisions\/67115"}],"wp:attachment":[{"href":"https:\/\/wpcalc.com\/en\/wp-json\/wp\/v2\/media?parent=66848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpcalc.com\/en\/wp-json\/wp\/v2\/categories?post=66848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpcalc.com\/en\/wp-json\/wp\/v2\/tags?post=66848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}