My solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    // function to calculate the score using lcm and gcd array\n    long long scoreCalculate(vector<int>&a,vector<int>&b,unordered_set<int>&st,unordered_map<int,int>&mp){\n        long long ans=1;\n        for(int ele:st){\n            ans*=pow(ele,a[mp[ele]]+b[mp[ele]]);\n        }\n        return ans;\n    }\n\n    long long maxScore(vector<int>& nums) {\n        int n=nums.size();\n        if(n==1)return nums[0]*nums[0];\n        // count array to count the frequency of each element \n        vector<int>count(31,0);\n        // set containing all prime number under 30\n        unordered_set<int>pri={2,3,5,7,11,13,17,19,23,29};\n        // map to get index corresponding to each prime no.\n        unordered_map<int,int>prime={{2,0},{3,1},{5,2},{7,3},{11,4},{13,5},{17,6},{19,7},{23,8},{29,9}};\n        \n        int k=0;//denotes no. of prime numbers\n\n\n        // 1<=nums[i]<=30 so we prime factorise all nums[i] and store prime factorization of each element \n        // to store we use vector in which index enotes the prime no. (can be found using map declared above) and value at index denotes the count of that prime no. in prime factorization of nums[i]\n        // to LCM  just find max count of each prime no. for all nums[i]\n        // to get GCD just take intersection/common of count of each prime no. for all element\n        // effect of removing 1 element  gcd   ---> can increase or remain same\n        //                               lcm   ----> can decrease or remain same\n        // so if removing 1 element does not increase gcd then their is no point in deleting it\n\n\n        // array to store prime number factorization of array\n        vector<vector<int>>factor(31,vector<int>(10,0));\n        // array to store the maximum count of each prime no. inorder to get LCM\n        vector<int>lcm(10,0);\n        // array to store the minmum count of each prime no. inorder to get GCD\n        vector<int>gcd(10,0);\n\n        // by default gcd has all 0 so if we take minimum it will give 0\n        // but we want common in all no. ---> first take 1st number then start taking common using it\n\n        // bool variable to denote whether 1st element is taken or not\n        bool first=false;\n\n        // iterate over all element\n        for(int i=0;i<n;i++){\n            // increse the count of nums[i]\n            count[nums[i]]++;\n\n            // don\'t calculate the effect of 1; \n            // as if no. of 1 =1 then delete this 1 and calculate score is our answer\n            // and if no. of 1>1 then gcd=1 and don\'t remove any element and calculate lcm give us our answer\n            // if count[nums[i]]>1 means we have already prime factorise nums[i] and nums[i] effect on gcd and lcm has been taken under concentration\n            if(nums[i]==1 || count[nums[i]]>1){\n                continue;\n            }else if(pri.count(nums[i])){\n                // if number if prime \n                factor[nums[i]][prime[nums[i]]]++;\n                k++; // inc the count of prime no.\n            }else{\n                // factorise nums[i] and store \n                for(int ele:pri){\n                    int temp=nums[i];\n                    while(temp%ele==0){\n                        factor[nums[i]][prime[ele]]++;\n                        temp/=ele;\n                    }\n                }\n            }\n            if(!first){\n                // if nums[i] is the first no. \n                for(int ele:pri){\n                    lcm[prime[ele]]=factor[nums[i]][prime[ele]];\n                    gcd[prime[ele]]=factor[nums[i]][prime[ele]];\n                }\n                first=true;\n            }else{\n                // calculate maximum and minimun count\n                for(int ele:pri){\n                    lcm[prime[ele]]=max(lcm[prime[ele]],factor[nums[i]][prime[ele]]);\n                    gcd[prime[ele]]=min(gcd[prime[ele]],factor[nums[i]][prime[ele]]);\n                }\n            }   \n        }\n        // calculate score \n        long long score=scoreCalculate(lcm,gcd,pri,prime);\n        if(count[1]==1){\n            // if count of 1 is 1 means then removing it will not decrese LCm but it can incrase gcd so it is the ideal choice for removing\n            return score;\n        }else if(count[1]>1 || k>2){\n            // if no. of 1 >1 or no. of prime no. >2 then even after removing 1 element gcd stil remain 1 don/t delete any element and calculate answer \n            score=1;\n            for(int ele:pri){\n                score*=pow(ele,lcm[prime[ele]]);\n            }\n            return score;\n        }\n        \n        for(int k=2;k<31;k++){\n            // if count of k>1 then removing it has no. impact on lcm and gcd so don\'t check this case\n       \n            // check if we delete k what will be the lcm and gcd\n            if(count[k]==1){\n                // empty the lcm and gcd array\n                for(int i=0;i<10;i++){\n                    lcm[i]=gcd[i]=0;\n                }\n                first=false;// initalaise the first \n                for(int i=2;i<31;i++){\n                    if(k==i || count[i]==0)continue;\n                    if(!first){\n                        for(int ele:pri){\n                            lcm[prime[ele]]=factor[i][prime[ele]];\n                            gcd[prime[ele]]=factor[i][prime[ele]];\n                        }\n                        first=true;\n                    }else{\n                        for(int ele:pri){\n                            lcm[prime[ele]]=max(lcm[prime[ele]],factor[i][prime[ele]]);\n                            gcd[prime[ele]]=min(gcd[prime[ele]],factor[i][prime[ele]]);\n                        }\n                    }  \n                }\n\n                long long temp=scoreCalculate(lcm,gcd,pri,prime);\n                if(score<temp)score=temp;\n            }\n        }\n        return score;\n    }\n};\n```
['C++']