Solve x ≡ a (mod m) Range

Computer Mathematics Hard 2 views
Back to Questions

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.

Sample Test Case

Input:
10 30 3 7
Output:
10

Constraints

m>0

Solutions (0)

No solutions submitted yet. Be the first!

Discussion (0)

No comments yet. Start the discussion!

Prev Next