Python Solution
```\nclass Solution:\n    def countDistinct(self, nums: List[int], k: int, p: int) -> int:\n        ans = 0\n        n = len(nums)\n        for i in range(n):\n
```\nclass Solution:\n    def countDistinct(self, nums: List[int], k: int, p: int) -> int:\n        ans = 0\n        n = len(nums)\n        for i in range(n):\n            temp2 = []\n            l = 0\n            check = set()\n            for j in range(i,n):\n                if i == 0:\n                    if nums[j]%p == 0:\n                        temp2.append(1)\n                    else:\n                        temp2.append(0)\n                    if temp2[l] <= k and nums[j] not in check:\n                        ans+=1\n                        check.add(nums[j])\n                else:\n                    if nums[j]%p == 0:\n                        temp2.append(temp1[l]+1)\n                    else:\n                        temp2.append(temp1[l])\n                    if temp2[l] <= k and tuple(nums[l:j+1]) not in check:\n                        ans+=1\n                        check.add(tuple(nums[l:j+1]))\n                l+=1\n            temp1 = list(temp2)\n    \n        return ans
[]