Brute Force
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nBrute Force\n\n# Comple
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nBrute Force\n\n# Complexity\n- Time complexity: $O(n^2)$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $O(1)$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nwhere $n$ is length of the $nums$ array.\n\n# Code\n```rust []\nimpl Solution {\n    pub fn max_score(nums: Vec<i32>) -> i64 {\n        let n = nums.len();\n\n        if n == 1 {\n            return (nums[0] * nums[0]) as i64;\n        }\n\n        let mut r = 0;\n\n        for i in 0..=n {\n            r = r.max(\n                Self::factor(i, &nums)\n            );\n        }\n\n        r\n    }\n\n    pub fn factor(i: usize, v: &Vec<i32>) -> i64 {\n        let n = v.len();\n\n        let mut d = if i == 0 {v[1] as i64} else {v[0] as i64};\n        let mut m = 1;\n\n        for j in 0..n {\n            if j != i {\n                d = Self::gcd(d, v[j] as i64);\n                m = Self::lcm(m, v[j] as i64);\n            }\n        }\n\n        m*d\n    }\n\n    pub fn gcd(a: i64, b: i64) -> i64 {\n        if a % b == 0 {\n            return b;\n        }\n\n        Self::gcd(b, a % b)\n    }\n\n    pub fn lcm(a: i64, b: i64) -> i64 {\n        (a * b) / Self::gcd(a, b)\n    }\n}\n```
['Array', 'Math', 'Number Theory', 'Rust']