✅ C++ Solution [Accepted]
\n\nclass Solution {\npublic:\n    \n    int countDistinct(vector<int>& nums, int & k, int & p) {\n        int n=nums.size();\n        set<vector<int>> s;\n    
```\n\nclass Solution {\npublic:\n    \n    int countDistinct(vector<int>& nums, int & k, int & p) {\n        int n=nums.size();\n        set<vector<int>> s;\n        vector<vector<int>> mat;\n        for (int i=0; i <n; i++)\n        {\n            vector<int> v;\n            int c=0;\n            for (int j=i; j<n; j++)\n            {\n                if(nums[j]%p==0) c++;\n                v.push_back(nums[j]);\n                if(c>k)\n                    break;\n                if(c<=k){\n                    s.insert(v);\n\n                }\n            \n            }\n        }\n        \n        \n        return s.size();\n    }\n};\n```\n\n![image](https://assets.leetcode.com/users/images/d99eec75-7f8c-410f-860b-e899499d4d7f_1651384255.2903054.png)\n
['Ordered Set']