// Numbas version: finer_feedback_settings {"name": "Blathnaid's copy of Solve three congruences using Chinese Remainder Theorem", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"rulesets": {"std": ["all", "fractionNumbers", "!collectNumbers", "!noLeadingMinus"]}, "ungrouped_variables": ["pans", "na", "nb", "nc", "ea", "rc", "ec", "n", "ra", "rb", "ans", "sc", "sb", "sa", "eb"], "parts": [{"prompt": "
Solve the following simultaneous congruences:
\\[\\begin{eqnarray*} x\\;&\\equiv&\\;\\var{ra}\\;&\\mod&\\;\\var{sa}\\\\ \\\\ x\\;&\\equiv&\\;\\var{rb}\\;&\\mod&\\;\\var{sb}\\\\ \\\\ x\\;&\\equiv&\\;\\var{rc}\\;&\\mod&\\;\\var{sc} \\end{eqnarray*} \\]
$x=\\;\\;$ [[0]]
Your value of $x$ should satisfy $0 \\leq x \\lt \\var{n}$
\n", "customName": "", "type": "gapfill", "sortAnswers": false, "customMarkingAlgorithm": "", "variableReplacements": [], "scripts": {}, "adaptiveMarkingPenalty": 0, "showFeedbackIcon": true, "useCustomName": false, "showCorrectAnswer": true, "gaps": [{"mustBeReduced": false, "customMarkingAlgorithm": "", "customName": "", "type": "numberentry", "mustBeReducedPC": 0, "minValue": "{ans}", "notationStyles": ["plain", "en", "si-en"], "adaptiveMarkingPenalty": 0, "showFeedbackIcon": true, "showCorrectAnswer": true, "showFractionHint": true, "marks": "4", "unitTests": [], "variableReplacementStrategy": "originalfirst", "extendBaseMarkingAlgorithm": true, "correctAnswerStyle": "plain", "maxValue": "{ans}", "variableReplacements": [], "scripts": {}, "useCustomName": false, "correctAnswerFraction": false, "allowFractions": false}], "marks": 0, "unitTests": [], "variableReplacementStrategy": "originalfirst", "extendBaseMarkingAlgorithm": true}], "statement": "", "tags": [], "name": "Blathnaid's copy of Solve three congruences using Chinese Remainder Theorem", "extensions": [], "variables": {"pans": {"name": "pans", "templateType": "anything", "group": "Ungrouped variables", "definition": "mod(ra*ea+rb*eb+rc*ec,n)", "description": ""}, "eb": {"name": "eb", "templateType": "anything", "group": "Ungrouped variables", "definition": "extendedgcd2(sb,nb)*nb", "description": ""}, "sa": {"name": "sa", "templateType": "anything", "group": "Ungrouped variables", "definition": "chcop(sb,sb,8,sb-1)", "description": ""}, "ra": {"name": "ra", "templateType": "anything", "group": "Ungrouped variables", "definition": "random(5..sa-1)", "description": ""}, "n": {"name": "n", "templateType": "anything", "group": "Ungrouped variables", "definition": "na*sa", "description": ""}, "rc": {"name": "rc", "templateType": "anything", "group": "Ungrouped variables", "definition": "random(1..sc-1)", "description": ""}, "rb": {"name": "rb", "templateType": "anything", "group": "Ungrouped variables", "definition": "random(2..sb-1)", "description": ""}, "sb": {"name": "sb", "templateType": "anything", "group": "Ungrouped variables", "definition": "random(12..20)", "description": ""}, "na": {"name": "na", "templateType": "anything", "group": "Ungrouped variables", "definition": "sb*sc", "description": ""}, "nb": {"name": "nb", "templateType": "anything", "group": "Ungrouped variables", "definition": "sa*sc", "description": ""}, "nc": {"name": "nc", "templateType": "anything", "group": "Ungrouped variables", "definition": "sa*sb", "description": ""}, "ec": {"name": "ec", "templateType": "anything", "group": "Ungrouped variables", "definition": "extendedgcd2(sc,nc)*nc", "description": ""}, "ans": {"name": "ans", "templateType": "anything", "group": "Ungrouped variables", "definition": "pans", "description": ""}, "sc": {"name": "sc", "templateType": "anything", "group": "Ungrouped variables", "definition": "chcop3(sa,sb,sb,2,sa-1)", "description": ""}, "ea": {"name": "ea", "templateType": "anything", "group": "Ungrouped variables", "definition": "extendedgcd2(sa,na)*na", "description": ""}}, "advice": "\n \n \nUsing the notation in Steps we have:
\n \n \n \n1) $n_1=\\var{sa},\\;n_2=\\var{sb},\\;n_3=\\var{sc}$ are coprime as they have no factors in common.
$n=n_1n_2n_3=\\var{n}$
2)
$N_1=\\var{sb}\\times \\var{sc}=\\var{na},\\;\tN_2=\\var{sa}\\times \\var{sc}=\\var{nb},\\;N_3=\\var{sa}\\times \\var{sb}=\\var{nc}$
3)
\n \n \n \nUsing the Extended Euclidean Algorithm for $N_1=\\var{na}$ and $n_1=\\var{sa}$ we find:
\\[\\simplify[std]{{extendedgcd2(sa,na)}* {na} +{extendedgcd1(sa,na)}*{sa}=1} \\Rightarrow E_1=\\var{extendedgcd2(sa,na)}\\times \\var{na}=\\var{ea}\\]
Using the Extended Euclidean Algorithm for $N_2=\\var{nb}$ and $n_2=\\var{sb}$ we find:
\\[\\simplify[std]{{extendedgcd2(sb,nb)}* {nb} +{extendedgcd1(sb,nb)}*{sb}=1} \\Rightarrow E_2=\\var{extendedgcd2(sb,nb)}\\times \\var{nb}=\\var{eb}\\]
Using the Extended Euclidean Algorithm for $N_3=\\var{nc}$ and $n_3=\\var{sc}$ we find:
\\[\\simplify[std]{{extendedgcd2(sc,nc)}* {nc} +{extendedgcd1(sc,nc)}*{sc}=1} \\Rightarrow E_3=\\var{extendedgcd2(sc,nc)}\\times \\var{nc}=\\var{ec}\\]\t
4)
Then the general solution is:\\[\\begin{eqnarray*}\n \n x&=& a_1 E_1+a_2 E_2+a_3 E_3\\;\\mod\\;n\\\\\n \n &=& \\simplify[std]{{ra}*{ea}+{rb}*{eb}+{rc}*{ec}}\\;\\mod\\;\\var{n}\\\\\n \n &=&\\var{ra*ea+rb*eb+rc*ec}\\;\\mod\\;\\var{n}\\\\\n \n &=& \\var{ans}\\;\\mod\\;\\var{n}\n \n \\end{eqnarray*}\n \n \\]
Solving three simultaneous congruences using the Chinese Remainder Theorem:
\n\\[\\begin{eqnarray*} x\\;&\\equiv&\\;b_1\\;&\\mod&\\;n_1\\\\ x\\;&\\equiv&\\;b_2\\;&\\mod&\\;n_2\\\\x\\;&\\equiv&\\;b_3\\;&\\mod&\\;n_3 \\end{eqnarray*} \\] where $\\operatorname{gcd}(n_1,n_2,n_3)=1$
", "licence": "Creative Commons Attribution 4.0 International"}, "variablesTest": {"condition": "", "maxRuns": 100}, "functions": {"extendedgcd2": {"language": "jme", "parameters": [["a", "number"], ["b", "number"]], "type": "number", "definition": "\n \n \n if((a|b) or (b|a),\n \n 1\n \n ,\n \n extendedgcd1(b,mod(a,b))-(extendedgcd2(b,mod(a,b))*floor(a/b))\n \n )\n \n "}, "mdescextgcd": {"language": "jme", "parameters": [["a", "number"], ["b", "number"], ["c1", "number"], ["c2", "number"], ["d1", "number"], ["d2", "number"], ["t", "number"]], "type": "string", "definition": "\n \n \n if (t=0, \n \n '\\n\\n$\\var{a}$ | $\\var{b}$ | $\\simplify[std]{{c1}a+{c2}b}$ | $\\simplify[std]{{d1}a+{d2}b}$ |