// Numbas version: exam_results_page_options {"name": "Apply extended Euclidean algorithm to find gcd", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"tags": [], "parts": [{"variableReplacements": [], "extendBaseMarkingAlgorithm": true, "variableReplacementStrategy": "originalfirst", "marks": 0, "prompt": "

Find $d$, using the Euclidean algorithm.

\n

$d=$ [[0]]

", "sortAnswers": false, "showFeedbackIcon": true, "type": "gapfill", "customMarkingAlgorithm": "", "gaps": [{"variableReplacements": [], "extendBaseMarkingAlgorithm": true, "variableReplacementStrategy": "originalfirst", "marks": "10", "allowFractions": false, "mustBeReduced": false, "showFeedbackIcon": true, "type": "numberentry", "notationStyles": ["plain", "en", "si-en"], "mustBeReducedPC": 0, "minValue": "{hcf}", "customMarkingAlgorithm": "", "maxValue": "{hcf}", "correctAnswerFraction": false, "unitTests": [], "showCorrectAnswer": true, "correctAnswerStyle": "plain", "scripts": {}}], "unitTests": [], "showCorrectAnswer": true, "scripts": {}}, {"variableReplacements": [], "extendBaseMarkingAlgorithm": true, "variableReplacementStrategy": "originalfirst", "marks": 0, "prompt": "

Find integers $x$ and $y$ such that $\\simplify{d={sa}*x+{sb}*y }$.

\n

$x=$ [[0]]

\n

$y=$ [[1]]

\n

If you use the extended Euclidean Algorithm, or, essentially equivalently, work backwards from the solution you found in a), then you will obtain suitable values for $x$ and $y$.

\n

After you finish the question, \"Reveal answers\" will give you a completely worked solution.

", "sortAnswers": false, "showFeedbackIcon": true, "type": "gapfill", "customMarkingAlgorithm": "", "gaps": [{"variableReplacements": [], "extendBaseMarkingAlgorithm": true, "variableReplacementStrategy": "originalfirst", "marks": "10", "allowFractions": false, "mustBeReduced": false, "showFeedbackIcon": true, "type": "numberentry", "notationStyles": ["plain", "en", "si-en"], "mustBeReducedPC": 0, "minValue": "{csa}", "customMarkingAlgorithm": "", "maxValue": "{csa}", "correctAnswerFraction": false, "unitTests": [], "showCorrectAnswer": true, "correctAnswerStyle": "plain", "scripts": {}}, {"variableReplacements": [], "extendBaseMarkingAlgorithm": true, "variableReplacementStrategy": "originalfirst", "marks": "10", "allowFractions": false, "mustBeReduced": false, "showFeedbackIcon": true, "type": "numberentry", "notationStyles": ["plain", "en", "si-en"], "mustBeReducedPC": 0, "minValue": "{csb}", "customMarkingAlgorithm": "", "maxValue": "{csb}", "correctAnswerFraction": false, "unitTests": [], "showCorrectAnswer": true, "correctAnswerStyle": "plain", "scripts": {}}], "unitTests": [], "showCorrectAnswer": true, "scripts": {"mark": {"script": "this.setCredit(0);\nthis.markingFeedback = [];\n\nvar x = parseFloat(this.gaps[0].studentAnswer);\nvar y = parseFloat(this.gaps[1].studentAnswer);\nvar total = variables.sa*x + variables.sb*y;\nif(total==variables.hcf) {\n this.setCredit(1,'Your answer is correct');\n this.gaps[0].settings.minvalue = this.gaps[0].settings.maxvalue = x;\n this.gaps[1].settings.minvalue = this.gaps[1].settings.maxvalue = y;\n} else {\n this.setCredit(0,'Your values of $x$ and $y$ give $\\\\simplify[]{{sa}'+x+' + {sb}'+y+'} = '+total+' \\\\neq h$');\n this.gaps[0].settings.minvalue = this.gaps[0].settings.maxvalue = x+1;\n this.gaps[1].settings.minvalue = this.gaps[1].settings.maxvalue = y+1;\n}\nthis.gaps[0].submit();\nthis.gaps[1].submit();", "order": "instead"}}}], "rulesets": {"std": ["all", "fractionNumbers", "!collectNumbers", "!noLeadingMinus"]}, "variablesTest": {"condition": "", "maxRuns": 100}, "metadata": {"licence": "Creative Commons Attribution 4.0 International", "description": "

Find the gcd $d$ of two positive integers $a$ and $b$ also find integers $x,y$ such that $ax+by=d$, using the extended Euclidean algorithm.

"}, "advice": "

We use the extended Euclidean Algorithm to get:

\n

{mdescextGCD(sa,sb,1,0,0,1)}

\n

Hence $d=\\var{hcf}$ and we have

\n

\\[ x= \\var{csa}, \\quad y=\\var{csb}\\]

\n

That is,

\n

\\[ \\simplify[!basic]{{sa}*{csa}+{sb}*{csb} = {hcf}} \\]

", "variable_groups": [], "statement": "

Let $d=\\text{gcd}(\\var{sa},\\var{sb})$.

\n

These numbers will differ each time you start this question anew, so you can practice this question as often as you want by clicking \"Try another question like this one\" below.

", "name": "Apply extended Euclidean algorithm to find gcd", "ungrouped_variables": ["bsa", "bsb", "csa", "csb", "hcf", "l1a", "l1b", "l2a", "l2b", "la", "lb", "sa", "sb", "ua", "ub"], "preamble": {"js": "", "css": ".extended-gcd td:nth-child(2) {\n border-right: 1px solid black;\n}\n.extended-gcd td {\n padding-left: 1em;\n padding-right: 1em;\n}\n.extended-gcd tr.state:not(:last-child) td {\n border-bottom: 1px dashed #ccc;\n}"}, "functions": {"extendedgcd2": {"type": "number", "language": "jme", "definition": "if((a|b) or (b|a),\n 1\n,\n extendedgcd1(b,mod(a,b))-(extendedgcd2(b,mod(a,b))*floor(a/b))\n)", "parameters": [["a", "number"], ["b", "number"]]}, "mdescextgcd": {"type": "html", "language": "javascript", "definition": "var table=$('');\nfunction disp(s){\n return Numbas.jme.display.exprToLaTeX(s,['unitFactor','zeroFactor','zeroTerm','basic'],scope);\n}\n\nfunction mdescextgcd(a,b,c1,c2,d1,d2){\n table.append('');\n if((a%b==0) || (b%a==0)) {\n return;\n }\n else {\n if(a');\n mdescextgcd(a,b%a,c1,c2,d1-fl*c1,d2-fl*c2);\n }\n else {\n var fl1=Math.floor(a/b);\n table.append('');\n mdescextgcd(a%b,b,c1-fl1*d1,c2-fl1*d2,d1,d2);}\n }\n}\nmdescextgcd(a,b,c1,c2,d1,d2);\n\nreturn table;\n", "parameters": [["a", "number"], ["b", "number"], ["c1", "number"], ["c2", "number"], ["d1", "number"], ["d2", "number"]]}, "extendedgcd1": {"type": "number", "language": "jme", "definition": "if((a|b) or (b|a),\n 0\n,\n extendedgcd2(b,mod(a,b))\n)", "parameters": [["a", "number"], ["b", "number"]]}}, "extensions": [], "variables": {"bsa": {"templateType": "anything", "definition": "round(sb/hcf)", "group": "Ungrouped variables", "name": "bsa", "description": ""}, "ua": {"templateType": "anything", "definition": "random(l1a..l2a)", "group": "Ungrouped variables", "name": "ua", "description": ""}, "l1a": {"templateType": "anything", "definition": "floor(bsa/4)", "group": "Ungrouped variables", "name": "l1a", "description": ""}, "bsb": {"templateType": "anything", "definition": "round(sa/hcf)", "group": "Ungrouped variables", "name": "bsb", "description": ""}, "l2b": {"templateType": "anything", "definition": "floor(3*bsb/4)", "group": "Ungrouped variables", "name": "l2b", "description": ""}, "csb": {"templateType": "anything", "definition": "extendedgcd2(sa,sb)", "group": "Ungrouped variables", "name": "csb", "description": ""}, "sb": {"templateType": "anything", "definition": "random(201..901)", "group": "Ungrouped variables", "name": "sb", "description": ""}, "l1b": {"templateType": "anything", "definition": "floor(bsb/4)", "group": "Ungrouped variables", "name": "l1b", "description": ""}, "la": {"templateType": "anything", "definition": "random(l1a..l2a)", "group": "Ungrouped variables", "name": "la", "description": ""}, "ub": {"templateType": "anything", "definition": "random(l1b..l2b)", "group": "Ungrouped variables", "name": "ub", "description": ""}, "l2a": {"templateType": "anything", "definition": "floor(3*bsa/4)", "group": "Ungrouped variables", "name": "l2a", "description": ""}, "csa": {"templateType": "anything", "definition": "extendedgcd1(sa,sb)", "group": "Ungrouped variables", "name": "csa", "description": ""}, "sa": {"templateType": "anything", "definition": "random(1001..2001)", "group": "Ungrouped variables", "name": "sa", "description": ""}, "hcf": {"templateType": "anything", "definition": "gcd(sa,sb)", "group": "Ungrouped variables", "name": "hcf", "description": ""}, "lb": {"templateType": "anything", "definition": "random(l1b..l2b)", "group": "Ungrouped variables", "name": "lb", "description": ""}}, "type": "question", "contributors": [{"name": "Bernhard von Stengel", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1054/"}, {"name": "Peter Allen", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/2724/"}]}]}], "contributors": [{"name": "Bernhard von Stengel", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1054/"}, {"name": "Peter Allen", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/2724/"}]}
$\\\\var{'+a+'}$$\\\\var{'+b+'}$$'+ disp(c1+'a+'+c2+'b')+'$$'+ disp(d1+'a+'+d2+'b')+'$
$\\\\var{'+a+'}$$\\\\var{'+b+'}-\\\\var{'+fl+'}\\\\times\\\\var{'+a+'}$$'+ disp(c1+'a+'+c2+'b')+'$$'+disp(d1+'a+'+d2+'b-'+fl+'('+c1+'a+'+c2+'b'+')')+'$
$\\\\var{'+a+'}-\\\\var{'+fl1+'}\\\\times\\\\var{'+b+'}$$\\\\var{'+b+'}$$'+disp(c1+'a+'+c2+'b-'+fl1+'('+d1+'a+'+d2+'b'+')')+'$$'+ disp(d1+'a+'+d2+'b')+'$