You are viewing a single comment's thread. Return to all comments →
Here is a simple solution written in Python 3. Surprisingly, many other solutions I see don't realize you don't need to iterate though each number - only the first half.
def divisorSum(self, n):
if n == 1:
factor_sum = 1 + n
for i in range(2, n//2 + 1):
if n % i == 0:
factor_sum += i
An elegant solution indeed. Thank you for sharing.