[Python] Check duplicate using Trie - O(N^2)
python\nclass TrieNode:\n    def __init__(self):\n        self.children = {}\n\nclass Solution:\n    def countDistinct(self, nums: List[int], k: int, p: int) ->
```python\nclass TrieNode:\n    def __init__(self):\n        self.children = {}\n\nclass Solution:\n    def countDistinct(self, nums: List[int], k: int, p: int) -> int:\n        trieRoot = TrieNode()\n        n = len(nums)\n        ans = 0\n\n        for i in range(n):\n            cntDivisible = 0\n            cur = trieRoot\n            for j in range(i, n):\n                if nums[j] % p == 0:\n                    cntDivisible += 1\n                if cntDivisible > k: break\n                if nums[j] not in cur.children:\n                    ans += 1\n                    cur.children[nums[j]] = TrieNode()\n                cur = cur.children[nums[j]]\n\n        return ans\n```\nComplexity\n- Time: `O(N^2)`, where `N` is length of `nums` array\n- Space: `O(N^2)`
['Python3']