Solve ax ≡ b (mod m). Fill the baby-step table j → aj, then take giant steps b·(a−n)i until one collides with the table. The collision gives x = i·n + j.
junior.md and professional.md for the correctness proof.
a=2, b=5, m=13 (answer x=9), a=3, b=1, m=13 (x=0), or a target outside 〈a〉 to watch the
“no solution” outcome after all n giant steps. Editing a, b, or m rebuilds the plan instantly.