Ctrl K

Squares at Divisor Positions

Easy
You are given an array values of length n. Number its positions starting from 1. Position i is special if n is divisible by i. Return the sum of the squares of the elements sitting at special positions.
Example 1
values=[3, 1, 4, 1, 5, 9] → 107

The length is 6, with divisors 1, 2, 3 and 6. Those places hold 3, 1, 4 and 9: 9 + 1 + 16 + 81 = 107.

Example 2
values=[2, 8, 6, 7, 5] → 29

The length 5 is prime, so only places 1 and 5 qualify: 4 + 25 = 29.

Constraints
  • 1 ≤ n = len(values) ≤ 50
  • 1 ≤ values[i] ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsConsistent Reading Triples EasyRepeated Block Run EasyXOR of Every Subset EasyThree Addends and a Later Total EasyEven Numbers From Digit Cards Easy
loading Python…
Input
values=[3, 1, 4, 1, 5, 9]
Expected
107

Run checks the first 3 tests in your browser. Submit checks all 98 tests on the server, hidden ones included.