1
2
3
4
5
6
7
8
9
10
def factor_sum(n):
  sum = 0
  p = 2
  while p*p <= n:
    if n % p == 0:
      sum += p
      while n % p == 0: n /= p
    p += 1
  if n > 1: sum += n
  return sum