QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 10

#13519. Tomki

Statistics

Pogromcy Algorytmów 所使用的软件是 Tomek W. 的作品。今年,它由 Tomek M. 负责维护。Tomek M. 非常努力,以确保比赛顺利进行。这也导致了 Tomek 最近经常做噩梦。昨天他梦见自己是一个在无限大棋盘上跳跃的棋子。该棋子可以进行的移动由两对整数 $(a, b)$ 和 $(c, d)$ 描述:站在格子 $(x, y)$ 上的棋子可以移动到格子 $(x + a, y + b)$、$(x - a, y - b)$、$(x + c, y + d)$ 或 $(x - c, y - d)$。Tomek 思考着(当然是在梦中),对于从格子 $(0, 0)$ 出发可以到达(可能需要经过多次跳跃)的、且不同于 $(0, 0)$ 的格子 $(x, y)$,何时 $|x| + |y|$ 的值最小。Tomek 浑身冷汗地醒来,因为他无法解决这个问题,并且不知道自己是否会远离点 $(0, 0)$ 太远,以至于来不及准备最后一轮的 Pogromcy Algorytmów 比赛。

任务

你的任务是编写一个程序,该程序:

  • 从标准输入读取两对不同于 $(0, 0)$ 的整数 $(a, b)$ 和 $(c, d)$,用于描述棋子的移动;
  • 确定一个不同于 $(0, 0)$ 的整数对 $(x, y)$,使得棋子可以从格子 $(0, 0)$ 到达(可能需要多次跳跃)格子 $(x, y)$,且 $|x| + |y|$ 的值最小;
  • 在标准输出中输出 $|x| + |y|$ 的值。

输入格式

标准输入的第一行包含四个整数:$a$、$b$、$c$ 和 $d$,满足 $-100\,000 \le a, b, c, d \le 100\,000$。

输出格式

你的程序应在标准输出的第一行(也是唯一一行)中输出一个整数,表示 $|x| + |y|$ 的最小值。

样例

输入样例 1

13 4 17 5

输出样例 1

2

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.