Trie
\nI have tried to depict map contents, cz I took way too much time to understand myself.\n\n\nint cnt = 0;\nclass Solution {\npublic:\n    struct Trie {\n    un
![image](https://assets.leetcode.com/users/images/ecc25561-f8db-4a66-b2b0-ea39a0bba0ab_1651578089.1177819.jpeg)\nI have tried to depict map contents, cz I took way too much time to understand myself.\n\n```\nint cnt = 0;\nclass Solution {\npublic:\n    struct Trie {\n    unordered_map<int, Trie*> ch;\n    \n    void insert(vector<int>& nums, int i, int k, int p) {\n        if (i == nums.size() || k - (nums[i] % p == 0) < 0)\n            return ;\n        if (ch[nums[i]] == nullptr) {\n           ch[nums[i]] = new Trie();\n          cnt++;\n        }\n        ch[nums[i]]->insert(nums, i + 1, k - (nums[i] % p == 0), p);\n    }\n};\nint countDistinct(vector<int>& nums, int k, int p) {\n    cnt = 0;\n    Trie t;\n    for (int i = 0; i < nums.size(); ++i)\n        t.insert(nums, i, k, p);\n    return cnt;\n}\n};\n```\n
[]