// Numbas version: finer_feedback_settings {"metadata": {"description": "
Given two numbers, find the gcd, then use Bézout's algorithm to find $s$ and $t$ such that $as+bt=\\operatorname{gcd}(a,b)$.
\nFinally, find all solutions of an equation $\\mod b$.
", "licence": "Creative Commons Attribution 4.0 International", "notes": ""}, "timing": {"allowPause": true, "timeout": {"action": "none", "message": ""}, "timedwarning": {"action": "none", "message": ""}}, "question_groups": [{"pickingStrategy": "all-ordered", "name": "", "pickQuestions": 0, "questions": [{"name": "Greatest common divisor and B\u00e9zout's algorithm", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}], "ungrouped_variables": ["s", "diff", "b1", "b", "n", "t", "a1", "bb", "c", "describeleast", "a", "least", "d", "k"], "variable_groups": [], "preamble": {"css": "", "js": ""}, "metadata": {"licence": "Creative Commons Attribution 4.0 International", "description": "Given two numbers, find the gcd, then use Bézout's algorithm to find $s$ and $t$ such that $as+bt=\\operatorname{gcd}(a,b)$. Finally, find all solutions of an equation $\\mod b$.
"}, "statement": "", "tags": ["euclidean algorithm", "gcd", "greatest common divisor", "Number theory", "number theory"], "parts": [{"type": "gapfill", "variableReplacements": [], "prompt": "\n\n\nFind $d = \\operatorname{gcd}(\\var{a},\\var{b})$, the greatest common divisor of $\\var{a}$ and $\\var{b}$:
\n\n\n\n$d = \\phantom{{}}$[[0]]
\n\n\n\nNow find integers $s$ and $t$ such that:
\n\n\n\n\\[\\var{a}s+\\var{b}t = d\\]
\n\n\n\n$s = \\phantom{{}}$[[1]] $, t = \\phantom{{}}$[[2]]$.$
\n\n\n ", "showCorrectAnswer": true, "variableReplacementStrategy": "originalfirst", "marks": 0, "gaps": [{"correctAnswerStyle": "plain", "type": "numberentry", "minValue": "d", "variableReplacementStrategy": "originalfirst", "mustBeReduced": false, "notationStyles": ["plain", "en", "si-en"], "maxValue": "d", "scripts": {}, "marks": 1, "variableReplacements": [], "showFeedbackIcon": true, "allowFractions": false, "showCorrectAnswer": true, "mustBeReducedPC": 0, "correctAnswerFraction": false}, {"correctAnswerStyle": "plain", "type": "numberentry", "minValue": "s", "variableReplacementStrategy": "originalfirst", "mustBeReduced": false, "notationStyles": ["plain", "en", "si-en"], "maxValue": "s", "scripts": {}, "marks": 1, "variableReplacements": [], "showFeedbackIcon": true, "allowFractions": false, "showCorrectAnswer": true, "mustBeReducedPC": 0, "correctAnswerFraction": false}, {"correctAnswerStyle": "plain", "type": "numberentry", "minValue": "t", "variableReplacementStrategy": "originalfirst", "mustBeReduced": false, "notationStyles": ["plain", "en", "si-en"], "maxValue": "t", "scripts": {}, "marks": 1, "variableReplacements": [], "showFeedbackIcon": true, "allowFractions": false, "showCorrectAnswer": true, "mustBeReducedPC": 0, "correctAnswerFraction": false}], "showFeedbackIcon": true, "scripts": {}}, {"type": "gapfill", "variableReplacements": [], "prompt": "\n\n\nFind all solutions $x$ of the following congruence:
\n\n\n\n\\[\\var{a}x \\equiv \\var{n} \\mod \\var{b} \\]
\n\n\n\nThe least solution $x$ such that $0 \\lt x \\lt \\var{b}$ is: [[0]]
\n\n\n\nWhat is the difference between two successive solutions? [[1]]
\n\n\n ", "showCorrectAnswer": true, "variableReplacementStrategy": "originalfirst", "marks": 0, "gaps": [{"correctAnswerStyle": "plain", "type": "numberentry", "minValue": "{least}", "variableReplacementStrategy": "originalfirst", "mustBeReduced": false, "notationStyles": ["plain", "en", "si-en"], "maxValue": "{least}", "scripts": {}, "marks": 1, "variableReplacements": [], "showFeedbackIcon": true, "allowFractions": false, "showCorrectAnswer": true, "mustBeReducedPC": 0, "correctAnswerFraction": false}, {"correctAnswerStyle": "plain", "type": "numberentry", "minValue": "{diff}", "variableReplacementStrategy": "originalfirst", "mustBeReduced": false, "notationStyles": ["plain", "en", "si-en"], "maxValue": "{diff}", "scripts": {}, "marks": 1, "variableReplacements": [], "showFeedbackIcon": true, "allowFractions": false, "showCorrectAnswer": true, "mustBeReducedPC": 0, "correctAnswerFraction": false}], "showFeedbackIcon": true, "scripts": {}}], "advice": "On applying the standard method for finding the $\\operatorname{gcd}$ of two numbers we have the following sequence:
\n{describegcd(a,b)}
\nThe last non-zero remainder is $\\var{d}$, so this is the $\\operatorname{gcd}$ of $\\var{a}$ and $\\var{b}$.
\nNow work backwards through those steps, rearranging them to find the remainders as linear combinations of the other numbers.
\nWhen you reach the last line you will have found $s$ and $t$ such that
\\[\\var{a}s+\\var{b}t = \\var{d}\\]
{describebezout(a,b)}
\nSo $s = \\var{s}$ and $t = \\var{t}$.
\nWe would like to find all the solutions $x$ of the equation
\\[\\var{a}x \\equiv \\var{n} \\mod \\var{b}.\\]
In order to solve such an equation first determine if there is a solution at all.
\nAn equation of the form $ax \\equiv n \\mod b$ has a solution if and only if $\\operatorname{gcd}(a,b)|n$.
\nSo the first task is to find $\\operatorname{gcd}(a,b)$ and see if it divides $n$. If not, there is no solution.
\nIn the first part, we found that $d = \\operatorname{gcd}(\\var{a},\\var{b}) = \\var{d}$.
\n$\\var{n} = \\var{d} \\times \\var{k}$, so the equation $\\var{a}x \\equiv \\var{n} \\mod \\var{b}$ has a solution.
\nNote that because $d|n$, then $n=kd$ for some integer $k$.
\nIn order to find a solution of $x$ go back to the first part and use the integers $s$ and $t$ such that
\n\\[ \\var{a}s + \\var{b}t = d. \\]
\nIf we multiply both sides of this equation by $k$ we find that
\n\\[ \\var{a}ks + \\var{b}kt = kd = n, \\]
\nand by taking both sides modulo $\\var{b}$ we see that
\n\\[ \\var{a}ks \\equiv n \\mod \\var{b}. \\]
\nSo $x = ks = \\var{k*s}$ is a solution of the equation.
\nThe difference between successive terms is $\\frac{\\var{b}}{\\var{d}} = \\var{diff}$.
\n{describeLeast}
", "variablesTest": {"maxRuns": 100, "condition": ""}, "rulesets": {}, "functions": {"describebezout": {"type": "html", "parameters": [["a", "number"], ["b", "number"]], "definition": "var list = $('First of all, the biggest number needs to go first: | $\\\\operatorname{gcd}(\\\\var{'+a+'},\\\\var{'+b+'}) = \\\\operatorname{gcd}(\\\\var{'+b+'},\\\\var{'+a+'}), $ | ');\nreturn describegcd(b,a);\n}\n\nif(a%b==0) {\ntable.append('
Finally, $\\\\var{'+b+'}$ divides into $\\\\var{'+a+'}$ exactly $\\\\var{'+a/b+'}$ times: | $\\\\var{'+a+'} = \\\\var{'+b+'} \\\\times \\\\var{'+a/b+'}.$ |
Divide $\\\\var{'+a+'}$ by $\\\\var{'+b+'}$ with remainder $\\\\var{'+(a%b)+'}$: | $\\\\var{'+a+'} = \\\\var{'+b+'} \\\\times \\\\var{'+Math.floor(a/b)+'} + \\\\var{'+(a%b)+'},$ |