Project Euler - Problem 12


/ 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 12
  4.  
  5. # Find the first triangle number to have over 500 divisors
  6. import math
  7.  
  8. i = 1
  9. tri = 0
  10. cnt = 2
  11. last = 0
  12. while True:
  13.  
  14. tri += i
  15. i += 1
  16. cnt = 0
  17. for z in range(1,int(math.sqrt(tri))):
  18. if tri % z == 0:
  19. cnt += 2
  20. if cnt > 499:
  21. break
  22.  
  23. print tri

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.