Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.6 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6925e2068081f40f549ced1c Challenge 138: Sum of Divisors 29 challenge-138

--description--

Given a positive integer, return the sum of all its divisors.

  • A divisor is any integer that divides the number evenly (the remainder is 0).
  • Only count each divisor once.

For example, given 6, return 12 because the divisors of 6 are 1, 2, 3, and 6, and the sum of those is 12.

--hints--

sum_divisors(6) should return 12.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(sum_divisors(6), 12)`)
}})

sum_divisors(13) should return 14.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(sum_divisors(13), 14)`)
}})

sum_divisors(28) should return 56.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(sum_divisors(28), 56)`)
}})

sum_divisors(84) should return 224.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(sum_divisors(84), 224)`)
}})

sum_divisors(549) should return 806.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(sum_divisors(549), 806)`)
}})

sum_divisors(9348) should return 23520.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(sum_divisors(9348), 23520)`)
}})

--seed--

--seed-contents--

def sum_divisors(n):

    return n

--solutions--

def sum_divisors(n):
    total = 0
    for i in range(1, n + 1):
        if n % i == 0:
            total += i
    return total