Cheerio Contest 2 P4 - Modulus Finding

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 1.0s
Memory limit: 512M

Author:
Problem type

You are given four integers A, B, C, D that satisfy the equations AmodX=B and CmodX=D, where X is a positive integer. Output all possible values of X. It is possible that there are none — in which case you do not need to output anything.

Constraints

For all subtasks:

  • 1A,B,C,D1012
  • B<A and D<C
Points Awarded Additional Constraints
3 points A=C and B=D
5 points 1A,B,C,D106
7 points No further constraints

Input Specification

The only line of input contains four integers A, B, C and D.

Output Specification

Output all possible values of X, each on their own line and in ascending order.

Sample Input

Copy
13 1 10 2

Sample Output

Copy
4

Explanation for Sample

131(mod4) and 102(mod4). It can be shown that this is the only possible value of X.


Comments

There are no comments at the moment.