#P8809. [蓝桥杯 2022 国 C] 近似 GCD
[蓝桥杯 2022 国 C] 近似 GCD
Problem Description
Xiao Lan has an array of length . A subarray is defined as an array formed by selecting one or more consecutive elements from the original array. The greatest common divisor (GCD) of an array refers to the GCD of all elements in the array. If, after changing at most one element in the array, the GCD of the array becomes , then is called the approximate GCD of this array. An array may have multiple possible approximate GCD values.
Specifically, to determine whether is an approximate GCD of a subarray:
- If the GCD of this subarray is exactly , then is its approximate GCD.
- If, after modifying one element in this subarray (it can be changed to any value), the GCD of the subarray becomes , then is the approximate GCD of this subarray.
Xiao Lan wants to know how many subarrays of with length at least have an approximate GCD equal to .
Input Format
The first line contains two integers , separated by a space, representing the length of array and the value of .
The second line contains integers , with a space between adjacent integers.
Output Format
Output one line containing one integer, representing how many subarrays of array with length at least have an approximate GCD equal to .
5 3
1 3 6 4 10
5
Hint
Sample Explanation
There are subarrays that satisfy the condition:
: After changing to , the GCD of this subarray becomes , so it satisfies the condition.
: After changing to , the GCD of this subarray becomes , so it satisfies the condition.
: The GCD of this subarray is , so it satisfies the condition.
: After changing to , the GCD of this subarray becomes , so it satisfies the condition.
: After changing to , the GCD of this subarray becomes , so it satisfies the condition.
Constraints
For of the testdata, .
For of the testdata, .
For all testdata, , .
Lanqiao Cup 2022 National Contest, Group C, Problem F.
Translated by ChatGPT 5