K Divisible Elements Subarrays | Python 
IntuitionWe need to count distinct subarrays where at most k numbers are divisible by p. Instead of checking all possible subarrays in a slow way, we can effici
# Intuition
We need to count distinct subarrays where at most k numbers are divisible by p. Instead of checking all possible subarrays in a slow way, we can efficiently track unique subarrays using a set.

# Approach
Use a set to store unique subarrays.

Loop through the array, picking a starting point for each subarray.

Extend the subarray step by step, keeping track of numbers divisible by p.

If more than k numbers are divisible by p, stop extending.

Convert each subarray into a tuple and store it in the set to avoid duplicates.

The total count of unique subarrays is the size of the set.

# Complexity
- Time Complexity: O(n²)

- Space complexity: O(n²)

# Code
```python []
class Solution(object):
    def countDistinct(self, nums, k, p):
        """
        :type nums: List[int]
        :type k: int
        :type p: int
        :rtype: int
        """
        seen = set()  # To store unique subarrays
        n = len(nums)

        for i in range(n):
            divisible_count = 0
            subarray = []
            for j in range(i, n):
                subarray.append(nums[j])
                if nums[j] % p == 0:
                    divisible_count += 1
                if divisible_count > k:
                    break  # Stop if more than k elements are divisible by p
                
                # Convert list to tuple (hashable) and add to set
                seen.add(tuple(subarray))

        return len(seen)

```
['Python']