1. import math
  2. from math import *
  3.  
  4. def p12e(int1):
  5.  
  6. # i and tri are for advancing the triangular number
  7. i = 1
  8. tri = 1
  9. factors = 1
  10.  
  11. # loop until there are more than int1 factors
  12. while factors <= int1:
  13. factors = 1
  14.  
  15. ##########
  16. # Calculate the number of factors that tri has.
  17.  
  18. prime = 1
  19. temp = tri
  20.  
  21. # STOP WHEN PRIME IS BIGGER THAN TRIANGLE:
  22.  
  23. t = 1
  24. while temp % 2 == 0:
  25. temp = temp / 2
  26. t += 1
  27.  
  28. factors *= t
  29.  
  30. t = 1
  31. while temp % 3 == 0:
  32. temp = temp / 3
  33. t += 1
  34.  
  35. factors *= t
  36.  
  37. ##########
  38.  
  39.  
  40. while prime <= tri:
  41.  
  42. prime = prime + 2
  43.  
  44. # DIVIDE AS MANY TIMES AS POSSIBLE
  45. t = 1
  46. while temp % prime == 0:
  47. temp = temp / prime
  48. t += 1
  49.  
  50. factors *= t
  51. ##########
  52.  
  53. # keep together
  54. i += 1
  55. tri += i
  56.  
  57. # when done, what is the triangle number that meets requirements?
  58. return tri - i