// Numbas version: finer_feedback_settings {"name": "Solve congruence in given range", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"parts": [{"stepsPenalty": 0, "scripts": {}, "gaps": [{"showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "correctAnswerFraction": false, "minValue": "{al}", "showCorrectAnswer": true, "marks": 1, "maxValue": "{al}"}, {"showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "correctAnswerFraction": false, "minValue": "{diff}", "showCorrectAnswer": true, "marks": 1, "maxValue": "{diff}"}, {"showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "correctAnswerFraction": false, "minValue": "{leans}", "showCorrectAnswer": true, "marks": 1, "maxValue": "{leans}"}, {"showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "correctAnswerFraction": false, "minValue": "{mans}", "showCorrectAnswer": true, "marks": 1, "maxValue": "{mans}"}], "type": "gapfill", "prompt": "
Find all the solutions in the range $0 \\leq x \\lt \\var{sb}$ of the following equation by answering the following questions :
\\[ \\var{sa}x \\equiv \\var{r}\\mod\\var{sb}\\]
Note that it is advisable to read Steps the first one or two times you try this exercise.
\nNumber of solutions $\\;=\\;$ [[0]]
\nWhat is the difference between successive solutions?
\nDistance $\\;=\\;$ [[1]]
\nInput here the least solution in the range $0 \\leq x \\lt \\var{sb}$
\n$x=\\;\\;$[[2]]
\nInput here the greatest solution in the range $0 \\leq x \\lt \\var{sb}$
\n$x=\\;\\;$[[3]]
", "steps": [{"type": "information", "prompt": "\n \n \nGiven an equation $ax\\;\\equiv\\;r \\;\\mod\\; n$ then the first step is to see if $a$ and $n$ are coprime.
\n \n \n \nIf they are then you simply multiply both sides of the equation by the inverse of $a$ in $\\mathbb{Z}_n$ and this gives the unique solution.
\n \n \n \nHowever if not coprime with $\\operatorname{gcd}(a,n) = \\alpha \\gt 1$ then the Extended Euclidean Algorithm gives:
\\[\\lambda a+\\mu n = \\alpha,\\;\\;\\lambda,\\;\\mu \\in \\mathbb{Z}.\\]
Now if $\\alpha | r$ and $r=\\beta \\times \\alpha$ then on multiplying the last equation by $\\beta$ we get:
\\[\\lambda \\times \\beta a + \\mu \\times \\beta n=\\alpha \\times \\beta = r\\]
Hence we see that $x= \\lambda \\times \\beta \\mod \\;n$ is a solution of our original equation.
\n \n \n \nAlso note that we can get other values of $\\lambda$ and $\\mu$ for $\\lambda a+\\mu n = \\alpha $ :
\\[\\left(\\lambda+i\\frac{n}{\\alpha}\\right) a+\\left(\\mu-i\\frac{a}{\\alpha}\\right) n = \\alpha,\\;\\;\\;i=0,1,\\ldots,\\alpha-1\\]
We see that there are $\\alpha$ possible values, $\\displaystyle{ \\lambda+i\\frac{n}{\\alpha},\\;\\;i=0,1,\\ldots,\\alpha-1}$ for the coefficient of $a$.
\n \n \n \nAt first sight we could multiply by $\\beta$ to get other solutions to our original equation, just as we did above.
\n \n \n \nBut if we look at $\\displaystyle{ \\left(\\lambda+i\\frac{n}{\\alpha}\\right)\\beta = \\lambda \\beta+i\\frac{n\\beta}{\\alpha}}$ then if
\n \n \n \n$\\operatorname{gcd}(\\alpha,\\beta) \\gt 1$ then there will be less than $\\alpha$ distinct values $\\mod\\;n$ for the solution.
\n \n \n \nThis is because $\\displaystyle{\\lambda \\beta+i\\frac{n\\beta}{\\alpha}=\\lambda \\beta+i\\frac{n\\beta_1}{\\alpha_1}}$ for $\\alpha_1 \\lt \\alpha$ and $\\operatorname{gcd}(\\alpha_1,\\beta_1)=1$.
\n \n \n \nIn this case we will get $\\alpha_1$ distinct solutions $\\mod\\;n$ rather than $\\alpha$ for $i=0,1\\dots,\\alpha_1-1$.
\n \n \n \nFor example, consider \\[\\displaystyle{4x\\; \\equiv\\;8 \\mod\\; 12}\\]
\n \n \n \nHere we have $\\alpha=\\operatorname{gcd}(4,12)=4$, $12-2\\times 4 = 4 \\Rightarrow \\lambda= -2=10 \\mod 12$ and $\\beta = 8/4=2$.
\n \n \n \nNote that $\\operatorname{gcd}(\\alpha,\\beta) = 2$ and $\\frac{\\beta}{\\alpha}=\\frac{1}{2}$ so $\\alpha_1=2$.
\n \n \n \nSo one solution is $\\lambda \\times \\beta = 10 \\times 2 = 20 = 8 \\mod 12$.
\n \n \n \nIf we try to form other solutions we have:
\n \n \n \n$\\displaystyle{\\lambda \\beta+i\\frac{n\\beta}{\\alpha} = 8+i\\frac{12\\times 2}{4}=8+6i}$ and we have only $2$ solutions rather than $4$
\n \n \n \ngiven by $8$ when $i=0$ and $14=2 \\mod 12$ when $i=1$. When $i=2$ we get $8 \\mod 12 $ again.
\n \n \n \nHowever, if the example you are trying has $\\operatorname{gcd}(\\alpha,\\beta)=1$ then we will get $\\alpha$ distinct solutions.
\n \n \n\n", "showCorrectAnswer": true, "marks": 0, "scripts": {}}], "showCorrectAnswer": true, "marks": 0}], "variables": {"mans": {"templateType": "anything", "group": "Ungrouped variables", "definition": "if(mans_first=sb,sb-diff,mans_first)", "name": "mans", "description": ""}, "ans2": {"templateType": "anything", "group": "Ungrouped variables", "definition": "mod(csa,sb)", "name": "ans2", "description": ""}, "ans3": {"templateType": "anything", "group": "Ungrouped variables", "definition": "mod(be*ans2,sb)", "name": "ans3", "description": ""}, "mess": {"templateType": "anything", "group": "Ungrouped variables", "definition": "\n\n\nif(csa<0,\n\n'$=\\\\var{mod(be*csa,sb)}\\\\;\\\\mod\\\\;\\\\var{sb}$.'\n\n,\n\n'.'\n\n)\n\n\n\n", "name": "mess", "description": ""}, "al": {"templateType": "anything", "group": "Ungrouped variables", "definition": "gcd(sa,sb)", "name": "al", "description": ""}, "sb": {"templateType": "anything", "group": "Ungrouped variables", "definition": "//this gives a number sb in the range sa+1 to 80 such that 2 <=gcd(a,b)<=5\nnco(sa,sa,2,5)", "name": "sb", "description": ""}, "mans_first": {"templateType": "anything", "group": "Ungrouped variables", "definition": "sb-mod(sb-ans3,diff)", "name": "mans_first", "description": ""}, "diff": {"templateType": "anything", "group": "Ungrouped variables", "definition": "round(sb/al)", "name": "diff", "description": ""}, "be": {"templateType": "anything", "group": "Ungrouped variables", "definition": "random(2..5)*al+1", "name": "be", "description": ""}, "r": {"templateType": "anything", "group": "Ungrouped variables", "definition": "al*be", "name": "r", "description": ""}, "leans": {"templateType": "anything", "group": "Ungrouped variables", "definition": "mod(ans3,diff)", "name": "leans", "description": ""}, "csb": {"templateType": "anything", "group": "Ungrouped variables", "definition": "extendedgcd2(sa,sb)", "name": "csb", "description": ""}, "csa": {"templateType": "anything", "group": "Ungrouped variables", "definition": "extendedgcd1(sa,sb)", "name": "csa", "description": ""}, "sa": {"templateType": "anything", "group": "Ungrouped variables", "definition": "random(2,4,3,5)*random(4..12)", "name": "sa", "description": ""}}, "ungrouped_variables": ["be", "mans", "mess", "ans2", "ans3", "csa", "al", "leans", "csb", "r", "sb", "diff", "sa", "mans_first"], "question_groups": [{"pickingStrategy": "all-ordered", "questions": [], "name": "", "pickQuestions": 0}], "name": "Solve congruence in given range", "functions": {"nco": {"type": "number", "language": "jme", "definition": "if(gcd(a,b)$\\\\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'+')')+'$ | ');\n mdescextgcd(a,b%a,c1,c2,d1-fl*c1,d2-fl*c2);\n }\n else {\nvar fl1=Math.floor(a/b);\ntable.append('
$\\\\var{'+a+'}-\\\\var{'+fl1+'}\\\\times\\\\var{'+b+'}$ | $\\\\var{'+b+'}$ | $'+disp(c1+'a+'+c2+'b-'+fl1+'('+d1+'a+'+d2+'b'+')')+'$ | $'+ disp(d1+'a+'+d2+'b')+'$ |