javascript brute force 2550ms
\nconst countDistinct = (a, k, p) => {\n    let n = a.length, se = new Set();\n    for (let i = 0; i < n; i++) {\n        for (let j = i; j < n; j++) {\n       
```\nconst countDistinct = (a, k, p) => {\n    let n = a.length, se = new Set();\n    for (let i = 0; i < n; i++) {\n        for (let j = i; j < n; j++) {\n            let sub = a.slice(i, j + 1);\n            if (ok(sub, k, p)) se.add(JSON.stringify(sub)); // transfer array to string to remove duplicates\n        }\n    }\n    return se.size;\n};\n\nconst ok = (a, k, p) => {\n    let cnt = 0;\n    for (const x of a) {\n        if (x % p == 0) cnt++;\n    }\n    return cnt <= k;\n};\n```
['JavaScript']