Advertisement
Isti115

21

Jul 15th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. def getPrimes(num):
  2.     primes = {}
  3.     i = 2
  4.     while i * i <= num:
  5.         while num % i == 0: num /= i; primes[i] = primes[i] + 1 if i in primes else 1
  6.         i += 1
  7.     if num != 1: primes[num] = primes[num] + 1 if i in primes else 1
  8.     return primes
  9.  
  10. def getDivisors(primes):
  11.     dl = []
  12.     cprimes = {}
  13.    
  14.     for p in primes:
  15.         cprimes[p] = 0
  16.    
  17.     full = False;
  18.    
  19.     while not full:
  20.         cd = 1
  21.        
  22.         for cp in cprimes:
  23.             cd *= cp ** cprimes[cp]
  24.        
  25.         dl.append(cd)
  26.        
  27.         full = True
  28.        
  29.         for cp in cprimes:
  30.             if full:
  31.                 if cprimes[cp] + 1 > primes[cp]:
  32.                     cprimes[cp] = 0
  33.                     full = True
  34.                 else:
  35.                     cprimes[cp] += 1
  36.                     full = False
  37.    
  38.     return dl
  39.  
  40. def getDivSum(x):
  41.     return sum(getDivisors(getPrimes(x))) - x
  42.  
  43. s = 0
  44.  
  45. for i in range(10000):
  46.     if i != getDivSum(i) and i == getDivSum(getDivSum(i)):
  47.         s += i
  48.         #print(i)
  49.  
  50. print(s)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement