1 second
256 megabytes
standard input
standard output
The boy Smilo is learning algorithms with a teacher named Brukhovich.
Over the course of the year, Brukhovich will administer n� exams. For each exam, its difficulty ai�� 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 11. 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 i� (1≤i≤n−11≤�≤�−1) such that gcd(ai,ai+1)=1���(��,��+1)=1, where gcd(x,y)���(�,�) is the greatest common divisor of integers x� and y�.
Brukhovich wants to minimize the sadness of the year of Smilo. To do this, he can set the difficulty of any exam to 00. However, Brukhovich doesn’t want to make his students’ lives too easy. Therefore, he will perform this action no more than k� times.
Help Smilo determine the minimum sadness that Brukhovich can achieve if he performs no more than k� operations.
As a reminder, the greatest common divisor (GCD) of two non-negative integers x� and y� is the maximum integer that is a divisor of both x� and y� and is denoted as gcd(x,y)���(�,�). In particular, gcd(x,0)=gcd(0,x)=x���(�,0)=���(0,�)=� for any non-negative integer x�.
The first line contains a single integer t� (1≤t≤1041≤�≤104) — the number of test cases. The descriptions of the test cases follow.
The first line of each test case contains two integers n� and k� (1≤k≤n≤1051≤�≤�≤105) — the total number of exams and the maximum number of exams that can be simplified, respectively.
The second line of each test case contains n� integers a1,a2,a3,…,an�1,�2,�3,…,�� — the elements of array a�, which are the difficulties of the exams (0≤ai≤1090≤��≤109).
It is guaranteed that the sum of n� across all test cases does not exceed 105105.
For each test case, output the minimum possible sadness that can be achieved by performing no more than k� operations.
1 0 2 2 0 5 5 2 1
In the first test case, a sadness of 11 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 00 can be achieved by simplifying the second and fourth exams.