values and a number divisor. Count the non-empty segments (contiguous pieces of the array) whose elements have a greatest common divisor of exactly divisor.
The GCD of a set of numbers is the largest positive integer that divides each of them. Segments with different bounds count separately.values=[12, 8, 6, 5, 4], divisor=4 → 2
Exactly 4 is the GCD of [12, 8] and [4]. The GCD of [8] alone is 8, and once 6 joins a segment, the GCD drops to 2.
values=[7, 7], divisor=7 → 3
All three segments, [7], [7] and [7, 7], have GCD 7.
values=[3, 5, 9], divisor=2 → 0
values) ≤ 1000values[i] ≤ 10⁹divisor ≤ 10⁹values=[12, 8, 6, 5, 4], divisor=4
2
Run checks the first 3 tests in your browser. Submit checks all 126 tests on the server, hidden ones included.