PivotOJ

Logaritam

시간 제한: 1000ms메모리 제한: 1024MB출처: COCI 2022-2023BOJ 27910

문제

Hrvoje has recently learned about the logarithm function. He really likes the property log(xy)=log(x)+log(y)\log(xy) = \log(x) + \log(y), for each pair of positive real numbers xx and yy.

He is actually not interested in the function itself, but in logarithmic sequences. A logarithmic sequence of length nn is a sequence of real numbers (a1,a2,,an)(a_1, a_2, \dots , a_n) for which axy=ax+aya_{xy} = a_x + a_y holds for every pair of positive integers xx and yy such that xy ≤ n. An example of a logarithmic sequence of length 66 is 0, 1, π, 2, 0.7, 1 + π.

For his homework, Hrvoje needed to write qq logarithmic sequences of length nn, however, after a long night of effort he woke up just to find out that Matej had changed exactly one element of each sequence. Hrvoje doesn’t have a lot of time to correct his homework, so he is interested in the least number of elements of each sequence he needs to change so the sequence becomes logarithmic again. Unfortunately, Matej had written his element with a pen, so Hrvoje cannot change that element of the sequence.

Hrvoje has forgotten which sequences he wrote for his homework so the only thing he knows is the number of sequences qq, the length of each sequence nn and the position xix_i of the element Matej had changed in the i-th sequence.

Note: It can be proven that for any starting logarithmic sequence the minimal number of changes is the same.

입력

In the first line there are two positive integers nn and qq (1 ≤ n ≤ 10^8, 1 ≤ q ≤ 10^4), the length of each sequence and the number of sequences.

In the ii-th of the next qq lines there is a positive integer xix_i (1 ≤ x_i ≤ n), the index of the element Matej had changed in the ii-th sequence.

출력

In the ii-th line output -1 if Hrvoje cannot change the other elements of the ii-th sequence such that the sequence becomes logarithmic again, otherwise output the minimal number of changes needed to make the sequence logarithmic again.

힌트

Clarification of the first example: If the starting sequence was 0, 1, π, 2, 0.7, 1 + π and Matej changes the fourth element to 88, Hrvoje can change the second element to 44 and the sixth to 4 + π, after which the sequence 0, 4, π, 8, 0.7, 4 + π will be logarithmic again.

예제

예제 1

입력
6 6
1
2
3
4
5
6
출력
-1
2
1
2
0
1

예제 2

입력
20 5
7
8
2
19
12
출력
1
9
9
0
5

예제 3

입력
10000 4
1234
2345
3456
7890
출력
15
148
3332
37
코드를 제출하려면 로그인하세요.