click below for solution

Sunday, 30 January 2022

New Year Concert Solution|codeforces #769 (div 2)

                                         D.  New Year Concert

time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

New Year is just around the corner, which means that in School 179, preparations for the concert are in full swing.

There are n classes in the school, numbered from 1 to n, the i-th class has prepared a scene of length ai minutes.

As the main one responsible for holding the concert, Idnar knows that if a concert has k scenes of lengths b1b2bk minutes, then the audience will get bored if there exist two integers l and r such that 1lrk and gcd(bl,bl+1,,br1,br)=rl+1, where gcd(bl,bl+1,,br1,br) is equal to the greatest common divisor (GCD) of the numbers blbl+1br1br.

To avoid boring the audience, Idnar can ask any number of times (possibly zero) for the t-th class (1tk) to make a new scene d minutes in length, where d can be any positive integer. Thus, after this operation, bt is equal to d. Note that t and d can be different for each operation.

For a sequence of scene lengths b1b2bk, let f(b) be the minimum number of classes Idnar has to ask to change their scene if he wants to avoid boring the audience.

Idnar hasn't decided which scenes will be allowed for the concert, so he wants to know the value of f for each non-empty prefix of a. In other words, Idnar wants to know the values of f(a1)f(a1,a2)f(a1,a2,,an).

Input

The first line contains a single integer n (1n2105) — the number of classes in the school.

The second line contains n positive integers a1a2an (1ai109) — the lengths of the class scenes.

Output

Print a sequence of n integers in a single line — f(a1)f(a1,a2)f(a1,a2,,an

Note

In the first test we can change 1 to 2, so the answer is 1.

In the second test:

  • [1] can be changed into [2],
  • [1,4] can be changed into [3,4],
  • [1,4,2] can be changed into [2,3,2].
Solution link below:

if 1st link is not work then click on another link

solution link 1


Solution link 2


Solution link 3

No comments:

Post a Comment