Ctrl K

Divisor Sum of Four-Divisor Numbers

Medium
You are given an array of positive integers numbers. Pick out the ones that have exactly four divisors (counting 1 and the number itself) and add up all the divisors of all those numbers. A number that appears several times is counted every time. If no number qualifies, return 0.
Example 1
numbers=[15, 9, 8] → 39

15 has divisors 1, 3, 5, 15: exactly four, summing to 24. 8 has 1, 2, 4, 8: also four, summing to 15. 9 has only three (1, 3, 9) and does not count. The total is 24 + 15 = 39.

Example 2
numbers=[10, 10, 1] → 36

Each 10 contributes 1 + 2 + 5 + 10 = 18, and repeats count separately: 36. The number 1 has a single divisor.

Example 3
numbers=[2, 4, 16] → 0

None of them has exactly four divisors: 2 has two, 4 has three, 16 has five.

Constraints
  • 1 ≤ len(numbers) ≤ 10⁴
  • 1 ≤ numbers[i] ≤ 10⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsTurn a Square Clockwise MediumPostfix Calculator MediumRoll an Array to the Right MediumPrimes Below a Bound MediumNth Number Built From Given Primes Medium
loading Python…
Input
numbers=[15, 9, 8]
Expected
39

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