Number Theory and Applications
Time limit0.2sMemory limit16 MB
Given two Gaussian integers up to 10^9 in each coordinate, output every greatest common divisor in lexicographic order.
- Level
Hard8 of 10
- Topics
- Number theory, Math, Divide and conquer, Sorting
- Solved
- No attempts yet
Problem
Let us apply number theory. A complex number whose real and imaginary parts are integers is called a Gaussian integer.
\begin{equation*} G=\left{x+yi:::x,y\in\mathbb{Z}\right},\qquad\text{where}\quad i^2=-1 \end{equation*}
The notions of divisor, common divisor, and greatest common divisor carry over from the integers to the Gaussian integers.
- For two Gaussian integers , if there is some Gaussian integer with , then is called a divisor of . The relation that is a divisor of is written .
- For two Gaussian integers , a Gaussian integer that is a divisor of both and is called a common divisor of and .
- A common divisor of two Gaussian integers is called a greatest common divisor if holds for every other common divisor .
Given two Gaussian integers, write a program that finds all of their greatest common divisors.
Input
The first line gives the number of test cases . There are at most 1,000 test cases.
From the second line through the -th line, each line gives one test case. Each test case consists of four integers between and , separated by spaces. This input corresponds to the Gaussian integers and . The cases and are not given.
Output
A Gaussian integer is printed by printing , a space, and then . For each test case, print the number of greatest common divisors on the first line, and print the greatest common divisors on the second line in lexicographic order. That is, is printed before when , or when and .
Hint
The greatest common divisor is not unique even among the integers. For example, if an integer is a greatest common divisor of two integers , then is also a greatest common divisor of .