C++ simple solution using set
Intuition\n Describe your first thoughts on how to solve this problem. \nSimply traversing through all subarrays and checking condition and updating answer\n# A
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSimply traversing through all subarrays and checking condition and updating answer\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe are traversing all subarrays using 2 loops of i and j. Whilr traversing in subarray using j, we keep a variable count which keeps record of no of elements in that subarray divisible by p. If count<k, then whether next element is divisible by p or not, we can use that subarray and push in set. If count is equal to k, then we can\'t insert another element in that subarray if it is divisible by p, so we check that if number is divisible by p, then we break or else we puch in subarray and insert in set>\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N^2)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(N^2) (worst case)\n# Code\n```\nclass Solution {\npublic:\n    int countDistinct(vector<int>& nums, int k, int p) {\n        set<vector<int>> s;\n        for(int i=0;i<nums.size();i++)\n        {\n            int count=0;\n            vector<int> temp;\n            for(int j=i;j<nums.size();j++)\n            {\n                if(count<k)\n                {\n                    temp.push_back(nums[j]);\n                    s.insert(temp);\n\n                    if(nums[j]%p==0)\n                    count++;\n                }\n                else if(count==k)\n                {\n                    if(nums[j]%p!=0)\n                    {\n                        temp.push_back(nums[j]);\n                        s.insert(temp);\n                    }\n                    else\n                    break;\n                }\n            }\n            temp.clear();\n        }\n        return s.size();\n    }\n};\n```\nPlease upvote if you liked solution
['Ordered Set', 'C++']