Swords
Contest: Codeforces Round 587 (Div. 3)
Difficulty rating: 1300
Tags: math

There were $$$n$$$ types of swords in the theater basement which had been used during the plays. Moreover there were exactly $$$x$$$ swords of each type. $$$y$$$ people have broken into the theater basement and each of them has taken exactly $$$z$$$ swords of some single type. Note that different people might have taken different types of swords. Note that the values $$$x, y$$$ and $$$z$$$ are unknown for you.

The next morning the director of the theater discovers the loss. He counts all swords — exactly $$$a_i$$$ swords of the $$$i$$$-th type are left untouched.

The director has no clue about the initial number of swords of each type in the basement, the number of people who have broken into the basement and how many swords each of them have taken.

For example, if $$$n=3$$$, $$$a = [3, 12, 6]$$$ then one of the possible situations is $$$x=12$$$, $$$y=5$$$ and $$$z=3$$$. Then the first three people took swords of the first type and the other two people took swords of the third type. Note that you don't know values $$$x, y$$$ and $$$z$$$ beforehand but know values of $$$n$$$ and $$$a$$$.

Thus he seeks for your help. Determine the minimum number of people $$$y$$$, which could have broken into the theater basement, and the number of swords $$$z$$$ each of them has taken.

Input format:
The first line of the input contains one integer $$$n$$$ $$$(2 \le n \le 2 \cdot 10^{5})$$$ — the number of types of swords.

The second line of the input contains the sequence $$$a_1, a_2, \dots, a_n$$$ $$$(0 \le a_i \le 10^{9})$$$, where $$$a_i$$$ equals to the number of swords of the $$$i$$$-th type, which have remained in the basement after the theft. It is guaranteed that there exists at least one such pair of indices $$$(j, k)$$$ that $$$a_j \neq a_k$$$.

Output format:
Print two integers $$$y$$$ and $$$z$$$ — the minimum number of people which could have broken into the basement and the number of swords each of them has taken.

Constraints:
Time limit: 2.0 s
Memory limit: 256.0 MB

Note:
In the first example the minimum value of $$$y$$$ equals to $$$5$$$, i.e. the minimum number of people who could have broken into the basement, is $$$5$$$. Each of them has taken $$$3$$$ swords: three of them have taken $$$3$$$ swords of the first type, and two others have taken $$$3$$$ swords of the third type.

In the second example the minimum value of $$$y$$$ is $$$1$$$, i.e. the minimum number of people who could have broken into the basement, equals to $$$1$$$. He has taken $$$7$$$ swords of the first type.

Example input:
3
3 12 6

Example output:
5 3

Example input:
2
2 9

Example output:
1 7

Editorial:
Firstly, let's notice that for the fixed value of $$$z$$$ our problem is reduced to the following: we are given $$$n$$$ numbers $$$a_1, a_2, \dots, a_n$$$. We need to choose such values $$$k_1, k_2, \dots, k_n$$$ that $$$a_1 + k_1 \cdot z = a_2 + k_2 \cdot z = \dots = a_n + k_n \cdot z$$$. And among all such values $$$k_1, k_2, \dots, k_n$$$ we need to choose values in a way to minimize $$$\sum\limits_{i=1}^{n}k_i$$$. And the sum of $$$k_i$$$ is $$$y$$$! Of course, for the fixed value $$$z$$$ the minimum sum of $$$k_i$$$ can be only one.
Let's start with $$$z=1$$$. It is obvious that if the maximum value in the array $$$a$$$ is $$$mx$$$ the value $$$k_i$$$ equals $$$mx - a_i$$$ (for $$$z=1$$$). Assume that each $$$k_i$$$ from $$$1$$$ to $$$n$$$ has some divisor $$$d$$$. Then if we multiply $$$z$$$ by $$$d$$$ and divide each $$$k_i$$$ by $$$d$$$ the answer will only become better. How to calculate this value of $$$z$$$ fast? We can see that this value equals to $$$gcd(k_1, k_2, \dots, k_n)$$$! And it can be proven that this value of $$$z$$$ is always optimal and we can easily determine $$$y$$$ for such $$$z$$$.
Time complexity: $$$O(n + \log max(a_i))$$$.