fork download
  1. import math
  2.  
  3. def factorization(n):
  4. ans = []
  5.  
  6. if n < 2: return []
  7. while n % 2 == 0:
  8. ans.append(2)
  9. n >>= 1
  10.  
  11. i = 3
  12. j = int(math.sqrt(n))
  13. while i <= j:
  14. while n % i == 0:
  15. ans.append(i)
  16. n /= i
  17. j = int(math.sqrt(n))
  18. i += 2
  19.  
  20. if n != 1:
  21. ans.append(int(n))
  22.  
  23. return ans
  24.  
  25. print(factorization(1000000007))
  26. print(factorization(1000000000039))
  27. print(factorization(44414370))
  28. print(factorization(44414370310900590))
  29.  
Success #stdin #stdout 0.08s 27712KB
stdin
Standard input is empty
stdout
[1000000007]
[1000000000039]
[2, 3, 3, 5, 7, 11, 13, 17, 29]
[2, 3, 3, 5, 7, 11, 13, 17, 29, 1000000007]