Java Solution | Set
\nclass Solution {\n    public int countDistinct(int[] nums, int k, int p) {\n        int res=0;\n        Set<String> set = new HashSet<>();\n        for(int i=
```\nclass Solution {\n    public int countDistinct(int[] nums, int k, int p) {\n        int res=0;\n        Set<String> set = new HashSet<>();\n        for(int i=0;i<nums.length;i++){\n            int cnt = 0;\n            StringBuilder sb = new StringBuilder();\n            for(int j = i;j<nums.length;j++){\n                sb.append(nums[j]).append(",");\n                if(nums[j] % p == 0) cnt++;\n                if(cnt > k) break;\n                set.add(sb.toString());\n            }\n        }\n        return set.size();\n    }\n}\n```
['Java']