PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000394. Ước chung lớn nhất của số nguyên Gauss (Gcd of Gaussian Integers)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Ước chung lớn nhất của số nguyên Gauss (Gcd of Gaussian Integers)

Gcd of Gaussian Integers

Source: Library Checker

Version: Phuoc Hung OJ Extended

Problem Statement

A Gaussian integer is a complex number a+bia+bi with integer a,ba,b and i2=−1i^2=-1.

Given A=a1+b1iA=a_1+b_1i and B=a2+b2iB=a_2+b_2i, print any greatest common divisor G=u+viG=u+vi in Z[i]\mathbb Z[i]: GG divides both inputs and every common Gaussian divisor divides GG.

Answers are not unique. Whenever GG is a valid answer, −G,iG,−iG-G,iG,-iG are also valid. When both inputs equal zero, the answer is 00.

Input

Four integers a1,b1,a2,b2a_1,b_1,a_2,b_2 on one line. PHOJ uses one input pair per file, unlike the source's multi-case wrapper.

Output

Two integers u,vu,v representing one valid Gaussian GCD. The special checker accepts all four unit multiples.

Subtasks

  • Subtask 1 (20 points): −50≤a1,b1,a2,b2≤50-50\le a_1,b_1,a_2,b_2\le50.

  • Subtask 2 (30 points): −100 000≤a1,b1,a2,b2≤100 000-100\,000\le a_1,b_1,a_2,b_2\le100\,000.

  • Subtask 3 (50 points): −109≤a1,b1,a2,b2≤109-10^9\le a_1,b_1,a_2,b_2\le10^9.

Examples

Example 1

Input

11 3 1 8

Output

2 1

Explanation

11+3i=(2+i)(5−i)11+3i=(2+i)(5-i) and 1+8i=(2+i)(2+3i)1+8i=(2+i)(2+3i), so 2+i2+i divides both. Its three unit multiples are also accepted.

Example 2

Input

6 0 0 4

Output

2 0

Explanation

Both 66 and 4i4i are divisible by the Gaussian integer 22. Outputting −2-2, 2i2i, or −2i-2i is equally correct.