Sum of Squares of Special Elements

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
Inputnums = [1,2,3,4]
Output21
There are exactly 3 special elements in nums: nums[1], nums[2], and nums[4], so the sum of their squares is 1 * 1 + 2 * 2 + 4 * 4 = 21.
Example 2
Inputnums = [2,7,1,19,18,3]
Output63
There are exactly 4 special elements in nums: nums[1], nums[2], nums[3], and nums[6], so the sum of their squares is 2 * 2 + 7 * 7 + 1 * 1 + 3 * 3 = 63.

Constraints

  • 1 <= nums.length == n <= 50
  • 1 <= nums[i] <= 50

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate