Javascript recursion solution
\nvar countDistinct = function(nums, k, p) {\n    let ans = [];\n    \n    let rec = (index,k,p,nums,ans,curr) => {\n        let val = nums[index];\n        let
```\nvar countDistinct = function(nums, k, p) {\n    let ans = [];\n    \n    let rec = (index,k,p,nums,ans,curr) => {\n        let val = nums[index];\n        let check = val%p;\n        let isdiv = false;\n        if(check == 0) isdiv=true;\n    \n        if(index == nums.length) {\n            if(curr.length>0){\n                ans.push(curr.join(","));\n            }\n            return;\n        }\n        \n        //take conditions\n        if(isdiv && k==0){\n          ans.push(curr.join(","));\n        } else if(isdiv){\n             curr.push(val)\n             rec(index+1,k-1,p,nums,ans,curr);\n             curr.pop()\n        } else {\n             curr.push(val)\n             rec(index+1,k,p,nums,ans,curr);\n             curr.pop()\n        }\n        \n        \n        //non take conditions\n        if(curr.length == 0){\n             rec(index+1,k,p,nums,ans,curr);\n        } else {\n            ans.push(curr.join(","));\n        }\n   \n    }\n    rec(0,k,p,nums,ans,[]);\n    let set = new Set(ans);\n   \n    return set.size\n};\n```
['Recursion', 'JavaScript']