#P10183. Avoiding Supermarket Delays
Avoiding Supermarket Delays
Avoiding Supermarket Delays
Little Z is running along a highway that has n supermarkets, with the i-th supermarket located at position ai. He starts at position 0 and runs to the right with a constant speed v (a positive integer) and covers v units per unit time. When Little Z passes a supermarket, if the time of passing is an odd number, he will be tempted to enter the supermarket, which leads to an undesirable outcome.
Your task is to determine the maximum possible value of v such that for every supermarket, the time at which Little Z arrives is an even integer. Formally, for each supermarket at position ai, let the time taken be ti = ai / v. We require that:
[ \frac{a_i}{v} = 2k \quad \text{for some integer } k \geq 1, ]
This condition is equivalent to requiring that v divides ai and that ai / v is even for all i. It can be observed that since each ai must be divisible by v and yield an even quotient, the maximum valid v is given by the greatest common divisor (gcd) of all the numbers ai/2.
inputFormat
The first line contains a single integer n (the number of supermarkets). The second line contains n space-separated integers a1, a2, ..., an representing the positions of the supermarkets. It is guaranteed that each ai is even and that v exists.
outputFormat
Output a single integer — the maximum valid speed v such that Little Z arrives at every supermarket at an even time.
sample
3
4 8 12
2
</p>