Tornjevi

시간 제한2초메모리 제한2048 MB

요약
각 탑마다 자신의 높이가 그 구간 전체의 최대공약수와 같은 가장 긴 연속 구간의 길이를 구한다.
난이도

어려움10점 중 8점

유형
정수론, 동적 계획법, 수학, 배열
정답자
아직 제출이 없습니다

문제

On a certain street, there are nn towers, numbered consecutively from 11 to nn. Each tower has its own height h_ih\_i, expressed in meters.

For a consecutive subsequence of towers numbered l,l+1,…,rl, l + 1, \dots , r, we say that the tower with number ii (l≤i≤rl ≤ i ≤ r) is good in that subsequence if it holds that h_i=gcd⁡(h_l,h_l+1,…,h_r)h\_i = \gcd (h\_l , h\_{l+1}, \dots , h\_r), where gcd⁡(a_1,a_2,…,a_k)\gcd (a\_1, a\_2, \dots , a\_k) denotes the greatest common divisor of the set of positive integers a_1,a_2,…,a_ka\_1, a\_2, \dots , a\_k.

Your task is to determine, for each i=1,2,…,ni = 1, 2, \dots , n, the size of the largest consecutive subsequence in which the tower with number ii is good, where the size of a consecutive subsequence is defined as the number of towers in that subsequence.

입력

In the first line, there is an integer nn (1≤n≤1061 ≤ n ≤ 10^6), the number of towers.

In the second line, there are nn integers, in order, h_1,h_2,…,h_nh\_1, h\_2, \dots , h\_n (1≤h_i≤1061 ≤ h\_i ≤ 10^6).

출력

In a single line, print the answer to the above-mentioned question for each i=1,2,…,ni = 1, 2, \dots , n, in order.

힌트

Clarification of the first example: In the first four towers, tower number 11 is good. Towers with numbers 22, 33, and 44 are good in the subsequence they form themselves. Tower 55 will be good in any arbitrary subsequence that contains it, so the answer will be 66 (the entire sequence).

예제2

  1. 예제 1

    입력
    6
    3 6 6 6 1 3
    
    예상 출력
    4 3 3 3 6 1
    
  2. 예제 2

    입력
    5
    10 2 10 15 5
    
    예상 출력
    1 3 1 1 3