O(n^2) python Trie
\nclass Solution:\n    def countDistinct(self, nums: List[int], k: int, p: int) -> int:\n        trie = {}\n        n = len(nums)\n        ans = 0\n        for 
```\nclass Solution:\n    def countDistinct(self, nums: List[int], k: int, p: int) -> int:\n        trie = {}\n        n = len(nums)\n        ans = 0\n        for start in range(n):\n            count = 0\n            cur = trie\n            for j in range(start, n):\n                num = nums[j]\n                if num % p == 0:\n                    count += 1\n                    \n                if count > k:\n                    break\n                \n                if num not in cur:\n                    cur[num] = {}\n                    ans += 1\n                cur = cur[num]\n                    \n        return ans \n```
['Trie', 'Python']