K Divisible Elements Subarrays

Given an integer array nums, an allowance k, and a divisor p, count the distinct contiguous value sequences that contain at most k elements divisible by p. Occurrences at different positions count once when their values are identical in the same order.

  • Input: nums = [1,2,3,4], k = 1, p = 2
  • Output: 8
Examples
Input: ["5","1"]
Output: 1
Hints

K Divisible Elements Subarrays

Given an integer array `nums`, an allowance `k`, and a divisor `p`, count the distinct contiguous value sequences that contain at most `k` elements divisible by `p`. Occurrences at different positions count once when their values are identical in the same order.