[语言月赛 202407] value

Luogu
IDLGB4009
Time1000ms
Memory512MB
DifficultyP1
2024分支结构循环结构语言月赛
小 A 发现他的国家的价值可以使用 $x, y, z, w$ 四个非负整数衡量。但是为了维持平衡,现在他想要让 $x$ 和 $z$,$y$ 和 $w$ 保持一个相对稳定的比例。 现在他想要知道,是否可以找到一个正整数 $c$,使得 $x = z \times c$ 且 $y = w \times c$。请你帮助他找到这个正整数。 ## Input 一行四个整数 $x, y, z, w$。 ## Output 一行一个整数。如果可以找到一个正整数 $c$ 满足题目的条件,则输出这个 $c$。否则输出 $-1$。 [samples] ## Background 从前有个荣光的王国,小 A 是里面的国王,今天他要赐予他的子民以价值。 ## Note ### 样例解释 - 可以发现 $9 = 3 \times 3, 6 = 3 \times 2$,$3$ 可以成为样例 1 的 $c$。 - 对样例 2,不能找到任何一个正整数 $c$ 满足题目条件。 - 需要注意 $x, y, z, w$ 有可能是 $0$。 ### 数据规模与约定 对 $100\%$ 的数据,保证 $0 \leq x, y, z, w \leq 10^3$,且 $x, y, z, w$ 不同时为 $0$。
Samples
Input #1
9 6 3 2
Output #1
3
Input #2
7 2 3 5
Output #2
-1
Input #3
0 6 0 2
Output #3
3
API Response (JSON)
{
  "problem": {
    "name": "[语言月赛 202407] value",
    "description": {
      "content": "小 A 发现他的国家的价值可以使用 $x, y, z, w$ 四个非负整数衡量。但是为了维持平衡,现在他想要让 $x$ 和 $z$,$y$ 和 $w$ 保持一个相对稳定的比例。 现在他想要知道,是否可以找到一个正整数 $c$,使得 $x = z \\times c$ 且 $y = w \\times c$。请你帮助他找到这个正整数。",
      "description_type": "Markdown"
    },
    "platform": "Luogu",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 524288
    },
    "difficulty": {
      "LuoguStyle": "P1"
    },
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "LGB4009"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "小 A 发现他的国家的价值可以使用 $x, y, z, w$ 四个非负整数衡量。但是为了维持平衡,现在他想要让 $x$ 和 $z$,$y$ 和 $w$ 保持一个相对稳定的比例。\n\n现在他想要知道,是否可以找到一个正整数 $c$,使得 $x = z \\times c$ 且 $y = w \\times c$。请你帮助他找到这个正整数。\n\n## Input\n\n一行四个整数 $x, y, z, w$。\n\n...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments