Solve x ≡ a (mod m) Range
Computer Mathematics
Hard
2 views
Problem Description
Find the smallest x in [L,R] such that x ≡ a mod m, else -1.
Input Format
Four integers L R a m.
Output Format
One integer x or -1.
Official Solution
Let r = normalized(a). Find first = L + ((r - L mod m + m) mod m). If first<=R print it else -1.
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!