O(n^2) : Rabin Karp (rolling  hash)
\n\n# Code\n\ntypedef long long ll;\nll mod = 1e11+7;\n\nclass Solution {\npublic:\n    int countDistinct(vector<int>& nums, int k, int p) {\n        set<ll>st;
\n\n# Code\n```\ntypedef long long ll;\nll mod = 1e11+7;\n\nclass Solution {\npublic:\n    int countDistinct(vector<int>& nums, int k, int p) {\n        set<ll>st;\n        int n = nums.size();\n\n        for(int i=0;i<n;i++){\n            ll hash = 0;\n            int cnt = 0;\n            for(int j=i;j<n;j++){\n                if(nums[j]%p == 0){\n                    cnt++;\n                }\n                if(cnt>k) break;\n                hash = (hash*201+nums[j])%mod;\n                st.insert(hash);\n            }\n        }\n        return st.size();\n    }\n};\n```\n\n# upvote if it\'s help you HAPPY CODING :)\n
['Rolling Hash', 'C++']