Solution
Complexity

Time complexity: O(n3)


Space complexity: O(n2)

Code
# Complexity
- Time complexity: $$O(n^3)$$

- Space complexity: $$O(n^2)$$

# Code
```python3 []
class Solution:
    def countDistinct(self, nums: List[int], k: int, p: int) -> int:
        res = set()
        for i in range(len(nums)):
            cur_sub = []
            cur_k = 0
            for j in range(i, len(nums)):
                if nums[j] % p == 0:
                    cur_k += 1
                if cur_k <= k:
                    cur_sub.append(nums[j])
                    res.add(tuple(cur_sub))
        return len(res)
```
['Hash Table', 'Hash Function', 'Python3']