Handle several solutions and GCD summaries
Solve linear congruences and combine prefixes with suffixes.
Understand the idea
For ax congruent to b modulo m, set g = gcd(a,m). There is no solution unless g divides b. Otherwise divide a, b, m by g, solve the reduced coprime equation, and recover g residues modulo m separated by m/g.
Trace a small example
6x congruent to 8 modulo 14 reduces to 3x congruent to 4 modulo 7. The reduced answer 6 gives residues 6 and 13 modulo 14. For a different task, GCD after deleting one array element combines the prefix before it and suffix after it.
Conditions and cost
Include O(g) output work when listing all solutions. GCD has no subtraction inverse, so a prefix GCD alone cannot remove an element. Prefix and suffix arrays use O(n) storage and O(n log V) work under a Euclidean bound.
Does 6x congruent to 5 modulo 14 have a solution?
Turn the idea into code
Maximize the GCD of [6,10,15] after deleting one element.
Give me a hint
Check the remaining pair in each case.
Show the explained solution
Deleting 6 yields 5; deleting 10 yields 3; deleting 15 yields 2. The maximum is 5.
Your notes
Mark complete when you can explain it yourself.