fork download
  1.  
  2. def divisors(N):
  3. """return the biggest prime divisor for numbers less than N"""
  4. result = [1 for x in xrange(N)]
  5. for d in xrange(2,N):
  6. if result[d] > 1: continue
  7. for j in xrange(d, N, d):
  8. result[j] = d
  9. return result
  10.  
  11.  
  12. divs = divisors(2000)
  13.  
  14. def factor(n, divisors=divs):
  15. result = []
  16. while n > 1:
  17. p = divisors[n]
  18. if p == 1:
  19. result.append(n)
  20. return result
  21. while n % p == 0:
  22. result.append(p)
  23. n /= p
  24. return result
  25.  
  26. print 1000, factor(1000)
  27. print 24, factor(24)
  28. print 17*31, factor(17*31)
  29.  
Success #stdin #stdout 0.01s 6356KB
stdin
Standard input is empty
stdout
1000 [5, 5, 5, 2, 2, 2]
24 [3, 2, 2, 2]
527 [31, 17]