#P10183. [YDOI R1] Running

    ID: 11366 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>数学O2优化最大公约数 gcd洛谷比赛

[YDOI R1] Running

Background

Little Z is going to run. He wants to outpace his classmates after school starts.

Problem Description

Little Z is running on a road. There are nn supermarkets on the road, and the position of the ii-th supermarket is aia_i. When the time at which Little Z passes a supermarket is odd, he will go shopping there, and then he will be outpaced by his classmates.

Little Z starts at position 00. Every unit of time, he runs vv units to the right.

You need to find the maximum value of vv such that, when Little Z passes each of the nn supermarkets, he never goes shopping.

It is required that vv must be a positive integer, and the time Little Z spends to reach any supermarket must be an integer. In other words, you need to ensure that the time when Little Z reaches any supermarket is even. Note that the initial time is 00.

Input Format

The input has n+1n+1 lines.

Line 11 contains one positive integer nn.

Lines 22 to n+1n+1 each contain one positive integer. The positive integer in line i+1i+1 is aia_i.

Output Format

The output has 11 line.

Output the maximum vv that satisfies the conditions. If there is no solution, output 1-1.

2
1 
2
-1
5
10 
20 
30
40
50
5

Hint

Sample Explanation

For sample 11, it can be proven that there is no speed that meets the requirements.

For sample 22, when v=5v=5, the times to reach supermarkets 11 to 55 are 22, 44, 66, 88, 1010, all of which are even, so the requirement is satisfied. It can be proven that there is no faster valid speed.

This problem uses bundled testdata.

Subtask ID nn\le aia_i\le Score
11 3×10183\times10^{18} 1010
22 2525 Guaranteed a12×106a_1\le 2\times 10^6
33 10410^4 2020
44 2×1062\times10^6 3×10183\times10^{18} 6060

For 100%100\% of the data, 1n2×1061 \le n \le 2\times10^6, 1a1<a2<<an1<an3×10181\le a_1<a_2<\dots<a_{n-1}<a_n\le3\times10^{18}. It is guaranteed that all inputs are positive integers.

Translated by ChatGPT 5