You will write a solver for two congruences, with moduli that may share a factor. It must also say when there is no solution.
The idea. Write and put it into . This gives , a linear congruence for . It is solvable when divides , and the answer is unique modulo .
Your tasks.
inverse(a, m). Return the inverse of modulo by trying , or None if there is none.solve_pair(a, m, b, n). Return the pair (x, L) where L is the lcm of and and , or None when there is no solution.sunzi(). Use solve_pair twice to solve , , , and return x.Run your code once to unlock the worked solution.
Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…