[Python3] Rolling Hash Simple Solution
python\nclass Solution:\n    POW = 397\n    MODULO = 100000000069\n    def countDistinct(self, nums: List[int], k: int, p: int) -> int:\n        arr = list(map(
```python\nclass Solution:\n    POW = 397\n    MODULO = 100000000069\n    def countDistinct(self, nums: List[int], k: int, p: int) -> int:\n        arr = list(map(lambda x: 1 if x % p == 0 else 0, nums))\n        ans_set = set[int]()\n        for i in range(len(arr)):\n            cnt_one = 0\n            hash1 = 0\n            for j in range(i, len(arr)):\n                hash1 = (hash1 * Solution.POW + nums[j] + (j + 1 - i)) % Solution.MODULO\n                if arr[j] == 1:\n                    cnt_one += 1\n                if cnt_one <= k:\n                    ans_set.add(hash1)\n                else:\n                    break\n\n        return len(ans_set)\n```\n![image](https://assets.leetcode.com/users/images/ec6fb932-cb83-4064-a182-a8aecec8e1e6_1666442926.7710102.png)\n
['Python3']