Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. import math
  2.  
  3. # A function to print all prime factors of
  4. # a given number n
  5. def primeFactors(n):
  6.  
  7. # Print the number of two's that divide n
  8. while n % 2 == 0:
  9. print (2),
  10. n = n / 2
  11.  
  12. # n must be odd at this point
  13. # so a skip of 2 ( i = i + 2) can be used
  14. for i in range(3,int(math.sqrt(n))+1,2):
  15.  
  16. # while i divides n , print i ad divide n
  17. while n % i== 0:
  18. print (i),
  19. n = n / i
  20.  
  21. # Condition if n is a prime
  22. # number greater than 2
  23. if n > 2:
  24. print (n)
  25.  
  26. # Driver Program to test above function
  27.  
  28. n = 194
  29. primeFactors(n)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement