We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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:
return 1
else:
factor_sum = 1 + n
for i in range(2, n//2 + 1):
if n % i == 0:
factor_sum += i
return factor_sum
Day 19: Interfaces
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.