#d11305. 稳定数组

稳定数组

Stable Array

Problem Description

Given nn positive integers a1,a2,…,ana_1, a_2, \dots, a_n, in one operation for every ii with 1≤i≤n1 \le i \le n we set ai=gcd⁡(ai,ai mod n+1)a_i = \gcd(a_i, a_{i \bmod n + 1}).

Find the minimum number of operations needed so that a1=a2=⋯=ana_1 = a_2 = \dots = a_n.

Input Format

The first line contains a positive integer nn.

The second line contains nn positive integers a1,a2,…,ana_1, a_2, \dots, a_n.

Output Format

One non-negative integer: the minimum number of operations.

Sample Input

4
16 24 10 5

Sample Output

3

Constraints

2≤n≤1062 \le n \le 10^6

1≤ai≤1061 \le a_i \le 10^6