#P1891E. Brukhovich and Exams
Brukhovich and Exams
No submission language available for this problem.
Description
The boy Smilo is learning algorithms with a teacher named Brukhovich.
Over the course of the year, Brukhovich will administer exams. For each exam, its difficulty is known, which is a non-negative integer.
Smilo doesn't like when the greatest common divisor of the difficulties of two consecutive exams is equal to . Therefore, he considers the sadness of the academic year to be the number of such pairs of exams. More formally, the sadness is the number of indices () such that , where is the greatest common divisor of integers and .
Brukhovich wants to minimize the sadness of the year of Smilo. To do this, he can set the difficulty of any exam to . However, Brukhovich doesn't want to make his students' lives too easy. Therefore, he will perform this action no more than times.
Help Smilo determine the minimum sadness that Brukhovich can achieve if he performs no more than operations.
As a reminder, the greatest common divisor (GCD) of two non-negative integers and is the maximum integer that is a divisor of both and and is denoted as . In particular, for any non-negative integer .
The first line contains a single integer () — the number of test cases. The descriptions of the test cases follow.
The first line of each test case contains two integers and () — the total number of exams and the maximum number of exams that can be simplified, respectively.
The second line of each test case contains integers — the elements of array , which are the difficulties of the exams ().
It is guaranteed that the sum of across all test cases does not exceed .
For each test case, output the minimum possible sadness that can be achieved by performing no more than operations.
Input
The first line contains a single integer () — the number of test cases. The descriptions of the test cases follow.
The first line of each test case contains two integers and () — the total number of exams and the maximum number of exams that can be simplified, respectively.
The second line of each test case contains integers — the elements of array , which are the difficulties of the exams ().
It is guaranteed that the sum of across all test cases does not exceed .
Output
For each test case, output the minimum possible sadness that can be achieved by performing no more than operations.
Note
In the first test case, a sadness of can be achieved. To this, you can simplify the second and fourth exams. After this, there will be only one pair of adjacent exams with a greatest common divisor (GCD) equal to one, which is the first and second exams.
In the second test case, a sadness of can be achieved by simplifying the second and fourth exams.