P27622 [洛谷] [Language Monthly Contest 202407] Value
普及-
题目描述

Problem Background

Once upon a time, there was a glorious kingdom, and Little A was the king within it. Today, he wants to bestow value upon his subjects.

Problem Description

King Little A has discovered that the value of his kingdom can be measured using four non-negative integers $x, y, z, w$. However, to maintain balance, he wants to keep $x$ and $z$, as well as $y$ and $w$, in a relatively stable ratio.

He wants to know if there exists a positive integer $c$ such that $x = z \times c$ and $y = w \times c$. Please help him find this positive integer.

Input Format

A single line containing four integers $x, y, z, w$.

Output Format

A single line containing one integer. If a positive integer $c$ can be found that satisfies the conditions of the problem, output this $c$. Otherwise, output $-1$.

Sample Input and Output

Sample Input #1

9 6 3 2

Sample Output #1

3

Sample Input #2

7 2 3 5

Sample Output #2

-1

Sample Input #3

0 6 0 2

Sample Output #3

3

Notes

Sample Explanation

  • It can be observed that $9 = 3 \times 3$ and $6 = 2 \times 3$, so $3$ can be the $c$ for Sample 1.
  • For Sample 2, no positive integer $c$ can satisfy the conditions of the problem.
  • Note that $x, y, z, w$ can be $0$.

Data Range and Constraints

For $100\%$ of the data, it is guaranteed that $0 \leq x, y, z, w \leq 10^3$, and $x, y, z, w$ are not all $0$ at the same time.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
9 6 3 2
样例输出
3