logaritam — COCI CONTEST_#5
Task type: batch | Time limit: 1 s | Memory limit: 512 MB | Difficulty: 16
Algorithms: prime, mathematics

# Task Logaritam

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

He is actually not interested in the function itself, but in logarithmic sequences. A logarithmic sequence of length $n$ is a sequence of real numbers $(a_1, a_2, \dots, a_n)$ for which $a_{xy} = a_x + a_y$ holds for every pair of positive integers $x$ and $y$ such that $xy \le n$. An example of a logarithmic sequence of length 6 is $0, 1, \pi, 2, 0.7, 1 + \pi$.

![](_page_0_Figure_5.jpeg)

For his homework, Hrvoje needed to write $q$ logarithmic sequences of length $n$, 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 $q$, the length of each sequence $n$ and the position $x_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.

## Input

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

In the $i$-th of the next $q$ lines there is a positive integer $x_i$ ($1 \le x_i \le n$), the index of the element Matej had changed in the $i$-th sequence.

## Output

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

### Scoring

| Subtask | Points | Constraints |
|---|---|---|
| 1 | 19 | $n \le 20, q \le 20$ |
| 2 | 26 | $q \le 8$ |
| 3 | 29 | $n \le 10^4$ |
| 4 | 36 | No additional constraints. |

![](_page_1_Picture_0.jpeg)

## Examples

| input | input | input |
|---|---|---|
| 6 6 | 20 5 | 10000 4 |
| 1 | 7 | 1234 |
| 2 | 8 | 2345 |
| 3 | 2 | 3456 |
| 4 | 19 | 7890 |
| 5 | 12 |  |
| 6 |  | output |
| output | output |  |
| -1 | 1 | 15 |
| 2 | 9 | 148 |
| 1 | 9 | 3332 |
| 2 | 0 | 37 |
| 0 | 5 |  |
| 1 |  |  |

#### Clarification of the first example:

If the starting sequence was $0, 1, \pi, 2, 0.7, 1 + \pi$ and Matej changes the fourth element to 8, Hrvoje can change the second element to 4 and the sixth to $4 + \pi$, after which the sequence $0, 4, \pi, 8, 0.7, 4 + \pi$ will be logarithmic again.

Starter code: