#P9179. [COCI 2022/2023 #5] Logaritam
[COCI 2022/2023 #5] Logaritam
Problem Description
A logarithmic sequence is defined as a sequence of length such that for all positive integers with , we have . An example of a logarithmic sequence of length is .
There are logarithmic sequences of length , but now in each sequence exactly one element has been changed. You are given the number of sequences , the sequence length , and the position of the changed element in each sequence. For each sequence, output the minimum number of positions that must be modified so that the sequence is still a logarithmic sequence, under the condition that the already changed element must not be modified.
Note: It can be proven that for any initial logarithmic sequence, after changing the same position, the minimum number of modifications needed to turn the sequence back into a logarithmic sequence (without modifying that position) is always the same.
Input Format
The first line contains two positive integers , representing the sequence length and the number of sequences.
The next lines each contain a positive integer , indicating the index of the modified element in the -th sequence.
Output Format
If the -th sequence cannot be turned into a logarithmic sequence without modifying the already changed element, output -1. Otherwise, output the minimum number of elements that need to be changed.
6 6
1
2
3
4
5
6
-1
2
1
2
0
1
20 5
7
8
2
19
12
1
9
9
0
5
10000 4
1234
2345
3456
7890
15
148
3332
37
Hint
Explanation for Sample :
Assume the initial sequence is . If the fourth element is changed to , then we can change the second element to and the sixth element to . The sequence becomes , which is a logarithmic sequence again.
| Subtask ID | Additional Constraints | Score |
|---|---|---|
| Sample only | ||
| No additional constraints |
Translated by ChatGPT 5