#P18093. [CCPC 2026 长春站] 无忧旋律
[CCPC 2026 长春站] 无忧旋律
Problem Description
Little and little are two girls who love music. To commemorate a memory that belongs only to the two of them, little wrote a melody for little .
Little recorded every note in the movement as an integer according to its pitch. She chose a phrase of length such that is a cyclic shift of the sequence , that is, there exists a non-negative integer such that . Then she repeated this phrase again and again, and took the first notes to obtain the original score .
For example, when , can be one of , , or . If and , then .
Before giving the melody to little , little wants to add a color of her own to it: she may perform any number of modifications, and in each modification she may change the note at some position of the score into any positive integer. After several modifications, the original score becomes the score that little finally hears.
Little heard this melody , and learned the number from little 's sleep talk. Now little wants to know the minimum number of notes little had to modify to turn the original score into the that she finally heard.
Input Format
The first line contains an integer (), the number of test cases.
Each test case consists of two lines:
- The first line contains two integers (), the length of the score and the length of the phrase.
- The second line contains integers (), the pitches of the notes that little finally hears.
It is guaranteed that the sum of over all test cases in a single test point does not exceed .
Output Format
For each test case, output a single line with one non-negative integer, the minimum number of notes that little modified.
8
6 3
2 3 1 2 3 1
5 3
1 2 3 1 3
5 4
4 3 2 1 4
6 3
1 3 1 3 1 3
5 2
1 1 1 1 1
6 4
1 2 3 4 5 6
6 2
172 723 593 904 219 576
5 3
3 1 1000000000 999999999 1
0
1
2
4
2
2
6
2
Hint
For the first test case, one can take . Then the original score is exactly , which is the same as the final score, so little did not modify any note.
For the second test case, one can take , obtaining . It suffices to change the last note into to obtain the final score, so the answer is .
For the third test case, one can take , obtaining . It suffices to change the -nd note into and the -th note into to obtain the final score, so the answer is .
Translated by QwenWork