#B4009. Balanced Proportions
Balanced Proportions
Balanced Proportions
In this problem, you are given four non-negative integers (x, y, z, w) representing certain values of a country. The task is to determine if there exists a positive integer (c) such that (x = z \times c) and (y = w \times c).
Note: If both (z) and (w) are zero, then (x) and (y) must also be zero. In this case, output (1) as a valid answer (since any positive integer would be valid, we choose the smallest one). Otherwise, if a valid (c) does not exist, output (-1).
inputFormat
The input consists of a single line containing four non-negative integers (x, y, z, w) separated by spaces.
outputFormat
Output a single integer: the positive integer (c) if it exists, otherwise output (-1).
sample
6 9 2 3
3