Project Euler - Problem 3


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #!/usr/bin/python
  2.  
  3. # Project Euler - Problem 3
  4. # What is the largest prime factor of a number?
  5.  
  6. print "\nProject Euler - Problem 3 "
  7. print "This short program finds the largest"
  8. print "prime factor of a specified integer."
  9. number = input("\nTo begin, Please enter a number: ")
  10. i = 2
  11. fact = 0
  12. n = number
  13.  
  14. while n > 1:
  15. if n % i == 0: # divisible
  16. if fact < i:
  17. fact = i
  18. n = n / i
  19. i = 2
  20. else:
  21. i = i + 1
  22.  
  23.  
  24. print fact

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.