You are given a 1-indexed integer array nums of length n. An element nums[i] of nums is called special if i divides n, i.e. n % i == 0. Return the sum of the squares of all special elements of nums.
Example 1
Input: nums = [1,2,3,4]
Output: 21
Explanation: The length is 4. Positions 1, 2, and 4 divide 4, so their values 1, 2, and 4 are special: 1*1 + 2*2 + 4*4 = 21.
Example 2
Input: nums = [2,7,1,19,18,3]
Output: 63
Explanation: The length is 6. Positions 1, 2, 3, and 6 divide 6, so values 2, 7, 1, and 3 are special: 2*2 + 7*7 + 1*1 + 3*3 = 63.
Example 3
Input: nums = [1,2,3,4,5,6]
Output: 50
Explanation: The length is 6. Positions 1, 2, 3, and 6 divide 6, so values 1, 2, 3, and 6 are special: 1*1 + 2*2 + 3*3 + 6*6 = 50.
An index i is special exactly when it divides the length n. Walk the 1-indexed positions once, and whenever i divides n, add that element's square to a running total.
Run checks all cases above. Submit evaluates all test cases.