C++ Simple and Clean Solution
\nclass Solution {\npublic:\n    vector<int> largestDivisibleSubset(vector<int>& nums) {\n        sort(nums.begin(), nums.end());\n        int n = nums.size();\
```\nclass Solution {\npublic:\n    vector<int> largestDivisibleSubset(vector<int>& nums) {\n        sort(nums.begin(), nums.end());\n        int n = nums.size();\n        \n        vector<int> dp(n, 1), prev_idx(n, -1), res;\n        int max_idx = 0;\n        \n        for (int i=1; i<n; i++) {\n\n            for (int j=0; j<i; j++) {\n                if ((nums[i] % nums[j] == 0) && (dp[i] < dp[j]+1)) {\n                    dp[i] = dp[j]+1;\n                    prev_idx[i] = j;\n                }\n            }\n            max_idx = dp[i] > dp[max_idx] ? i : max_idx;\n        }\n        \n        int i = max_idx;\n        while (i >= 0) {\n            res.push_back(nums[i]);\n            i = prev_idx[i];\n        }\n        \n        return res;\n    }\n};\n```
['C']