#P11600. Meteor Shower
Meteor Shower
Meteor Shower
Fwb has designed a stunning meteor shower by launching meteors in the sky and placing fireworks on the ground. When a meteor collides with a firework, a unique and beautiful scene unfolds.
To make the display more impressive while minimizing resource usage, the meteors are launched in a fixed arithmetic progression: the first meteor is always launched at position 1, and if the meteor interval is \(k\), then after a meteor is launched at position \(i\), the next one is at \(i+k\). In order to guarantee that every firework is hit by a meteor, each firework's position \(p\) must satisfy the condition
\(p \equiv 1 \; (\bmod\; k)\)
This means that \(k\) must be a divisor of \(p-1\) for every firework position \(p\). In addition, to minimize the number of meteors launched, you should choose the largest possible \(k\) that satisfies this condition.
If the maximum firework position is \(L\), then the number of meteors launched will be
\(\frac{L-1}{k} + 1\)
Your task is to determine the minimum number of meteors that need to be launched and the corresponding meteor interval \(k\).
inputFormat
The input consists of two lines:
- The first line contains a positive integer \(n\) denoting the number of fireworks.
- The second line contains \(n\) space-separated integers, representing the positions of the fireworks on the number line.
It is guaranteed that the fireworks positions allow a valid solution (i.e. each firework position \(p\) satisfies \(p \equiv 1 \; (\bmod\; k)\) for some positive integer \(k\)).
outputFormat
Output two space-separated integers:
- The minimum number of meteors that need to be launched.
- The meteor interval \(k\) used.
sample
3
1 7 13
3 6