Easy and Fast Cpp solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n1.Calculate the total GCD of the entire array using a helper function.\n2
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1.Calculate the total GCD of the entire array using a helper function.\n2.Calculate the total LCM of the entire array using another helper function.\n3.Compute the initial factor score using the total GCD and total LCM.\n4.Loop through each element in the array, treating each as a candidate for removal.\n5.Create a temporary array excluding the current element.\nFor the modified array (after removing the element), calculate the GCD and LCM using the helper functions.\n6.Compare it with the current maximum factor score and update.\n7.return the maximum factor score obtained.\n\n# Complexity\n- Time complexity:\nO(n2)\n\n\n- Space complexity:\nO(n)\n\n# Code\n```cpp []\n\n\nclass Solution {\npublic:\n    int calculateGCD(const vector<int>& nums) {\n        int gcd_val = nums[0];\n        for (int i = 1; i < nums.size(); ++i) {\n            gcd_val = gcd(gcd_val, nums[i]);\n        }\n        return gcd_val;\n    }\n\n    long long calculateLCM(const vector<int>& nums) {\n        long long lcm_val = nums[0];\n        for (int i = 1; i < nums.size(); ++i) {\n            lcm_val = (lcm_val * nums[i]) / gcd(static_cast<long long>(lcm_val), static_cast<long long>(nums[i]));\n        }\n        return lcm_val;\n    }\n\n    long long maxScore(vector<int>& nums) {\n        int totalGCD = calculateGCD(nums);\n        long long totalLCM = calculateLCM(nums);\n\n        long long maxFactorScore = 1LL * totalGCD * totalLCM;\n        \n        for (int i = 0; i < nums.size(); ++i) {\n            vector<int> temp;\n            for (int j = 0; j < nums.size(); ++j) {\n                if (i != j) temp.push_back(nums[j]);\n            }\n\n            if (!temp.empty()) {\n                int gcd = calculateGCD(temp);\n                long long lcm = calculateLCM(temp);\n                maxFactorScore = max(maxFactorScore, 1LL * gcd * lcm);\n            }\n        }\n        \n        return maxFactorScore;\n    }\n};\n\n\n```
['C++']