2862. Maximum Element-Sum of a Complete Subset of Indices Hard

@problem@discussion
#Array#Math#Number Theory



1/**
2 * [2862] Maximum Element-Sum of a Complete Subset of Indices
3 *
4 * You are given a 1-indexed array nums. Your task is to select a complete subset from nums where every pair of selected indices multiplied is a <span data-keyword="perfect-square">perfect square,</span>. i. e. if you select ai and aj, i * j must be a perfect square.
5 * Return the sum of the complete subset with the maximum sum.
6 *  
7 * <strong class="example">Example 1:
8 * <div class="example-block">
9 * Input: <span class="example-io">nums = [8,7,3,5,7,2,4,9]</span>
10 * Output: <span class="example-io">16</span>
11 * Explanation:
12 * We select elements at indices 2 and 8 and 2 * 8 is a perfect square.
13 * </div>
14 * <strong class="example">Example 2:
15 * <div class="example-block">
16 * Input: <span class="example-io">nums = [8,10,3,8,1,13,7,9,4]</span>
17 * Output: <span class="example-io">20</span>
18 * Explanation:
19 * We select elements at indices 1, 4, and 9. 1 * 4, 1 * 9, 4 * 9 are perfect squares.
20 * </div>
21 *  
22 * Constraints:
23 * 
24 * 	1 <= n == nums.length <= 10^4
25 * 	1 <= nums[i] <= 10^9
26 * 
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/maximum-element-sum-of-a-complete-subset-of-indices/
31// discuss: https://leetcode.com/problems/maximum-element-sum-of-a-complete-subset-of-indices/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36    pub fn maximum_sum(nums: Vec<i32>) -> i64 {
37        
38    }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_2862() {
49    }
50}
51


Back
© 2025 bowen.ge All Rights Reserved.