QOJ.ac

QOJ

حد الوقت: 2.0 s حد الذاكرة: 256 MB مجموع النقاط: 100 قابلة للهجوم ✓

#7204. GCD 是个笑话

الإحصائيات

在数学中,艾森斯坦整数(以 Gotthold Eisenstein 命名,也称为欧拉整数,以 Leonhard Euler 命名)是形式为 $z = a + b\omega$ 的复数,其中 $a$ 和 $b$ 均为整数。 $a_1 + b_1\omega$ 与 $a_2 + b_2\omega$ 的乘积为 $(a_1a_2 - b_1b_2) + (a_1b_2 + a_2b_1 - b_1b_2)\omega$。例如,$(5 + 7\omega) \times (6 + 9\omega) = -33 + 24\omega$,$(1 + 0\omega) \times (9 - 14\omega) = 9 - 14\omega$ 以及 $(-1 + 0\omega) \times (0 - 1\omega) = 0 + 1\omega$。 如果 $U, V$ 和 $W$ 是艾森斯坦整数,且满足 $U \times V = W$,则称 $U$(或 $V$)是 $W$ 的一个约数。 对于每个艾森斯坦整数,我们总能找到一些约数。因为 $1 + 0\omega$ 是任何艾森斯坦整数的约数。此外,每个艾森斯坦整数都是 $0 + 0\omega$ 的约数。因为我们可以发现 $(1 + 0\omega) \times (a + b\omega) = a + b\omega$ 且 $(0 + 0\omega) \times (a + b\omega) = 0 + 0\omega$。 如果艾森斯坦整数 $G$ 既是 $P$ 的约数又是 $Q$ 的约数,则称 $G$ 是 $P$ 和 $Q$ 的公约数。 在艾森斯坦整数中,$P$ 和 $Q$ 的最大公约数是一个公约数 $G_g$,使得 $P$ 和 $Q$ 的每一个公约数也都是 $G_g$ 的约数。两个艾森斯坦整数的最大公约数可能不止一个。 你的任务是求出给定一对艾森斯坦整数的一个最大公约数。

输入格式

输入的第一行包含一个整数 $T$,表示测试用例的数量。每个测试用例包含一行,包含四个整数 $a_1, b_1, a_2$ 和 $b_2$,表示一对艾森斯坦整数 $a_1 + b_1\omega$ 和 $a_2 + b_2\omega$。($T \le 50000, -10^7 \le a_1, b_1, a_2, b_2 \le 10^7$)

输出格式

对于每个测试用例,输出一行,包含两个整数 $a$ 和 $b$,表示最大公约数 $a + b\omega$。如果存在多个最大公约数,请选择 $a^2 + b^2$ 最大的那个艾森斯坦整数;如果仍有多个选项,请选择 $a$ 最大的那个;如果仍有多个选项,则选择 $b$ 最大的那个。

样例

样例输入 1

3
-4 2 2 -1
1 1 1 1
1 2 3 4

样例输出 1

3 2
1 1
1 1

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.