#P10916. 椰子

椰子

Background

As everyone knows, a coconut is a coconut, but this seems to have nothing to do with the problem.

Problem Description

You are given a sequence aa of length nn. We guarantee that every number from 11 to nn appears in aa exactly once. For each 1≤i≤n1\le i\le n, after changing the value ii in the sequence to 11, find how many different subarray gcd⁡\gcd values the sequence has.

More precisely, let AxA^x be the sequence after changing the number with value xx to 11. Define the set $S_x=\{\gcd\limits_{i=l}^r(A^x_i)|1\le l\le r\le n\}$. Compute ∣Si∣|S_i| for all ii.

Input Format

The first line contains a positive integer nn, the length of the permutation.

The next line contains nn positive integers, the sequence aa.

Output Format

Output one line with nn integers in total. The ii-th integer denotes the number of different subarray gcd⁡\gcd values after changing the number with value ii to 11.

3
3 1 2
3 2 2
6
3 6 4 1 5 2
6 6 5 5 5 5

Hint

Sample Explanation 1

After changing 11 to 11, there are 33 different subarray gcd⁡\gcd values: {1,2,3}\{1,2,3\}. They can correspond to subarrays [1,3][1,3], [3,3][3,3], and [1,1][1,1], respectively.

After changing 22 to 11, there are 22 different subarray gcd⁡\gcd values: {1,3}\{1,3\}. They can correspond to subarrays [2,3][2,3] and [1,1][1,1], respectively.

After changing 33 to 11, there are 22 different subarray gcd⁡\gcd values: {1,2}\{1,2\}. They can correspond to subarrays [1,2][1,2] and [3,3][3,3], respectively.

Constraints and Notes

This problem uses bundled testdata.

Subtask\text{Subtask} Score Constraints Special Property
11 1010 n≤20n\le 20 No special restrictions.
22 2020 n≤200n\le 200
33 3030 n≤2000n\le 2000
44 2020 No special restrictions. AA.
55 No special restrictions.

AA: For all 1≤i≤n1\le i\le n, we have ai=ia_i=i.

For all testdata, 2≤n≤5×1052\le n\le 5\times 10^5. We guarantee that every number from 11 to nn appears in aa exactly once.

Translated by ChatGPT 5