Simple using prefix count 🟢✔️
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def countDistinct(self, nums: List[int], k: int, p: int) -> int:
        n=len(nums)
        prefixCount=[0]*n
        tracedup=set()
        c=0
        for i in range(n):
            if nums[i]%p==0:
                c+=1
            prefixCount[i]=c
        for i in range(n):
            a=i
            b=n-1
            while(a<=b):
                if i>0:
                    res=prefixCount[b]-prefixCount[a-1]
                else:
                    res=prefixCount[b]-0
                if res<=k:
                    if tuple(nums[a:b+1]) not in tracedup:
                        #print(nums[a:b+1])
                        tracedup.add(tuple(nums[a:b+1]))
                b-=1

        return(len(tracedup))

                    
```
['Python3']