title: How to improve running time for Project Euler exercises
body: <p>I am experiencing some running time issues with Project Euler. The exercise can be found here:
  <a href="https://projecteuler.net/problem=12" rel="nofollow noreferrer">Project Euler exercise 12</a>. My solution is: </p>
  
  <pre><code>def triangularnr(n):
      T_n = n*(n+1)/2     #Function to calculate triangular numbers 
      return T_n
  
  for n in range(1,1*10**8):  #Nr with over 500 divisors is large, large range required
      count = 2   #Every nr is divisible by itself and by 1, thus initially count = 2 
      for i in range(2,int(triangularnr(n))): #Defining i to find divisors 
          if triangularnr(n)%i == 0:
              count+=1 #Incrementing count to count the nr of divisors 
      if count &gt; 500: #If a triangularnr has over 500 divisors we want to print the nr
          print(triangularnr(n))
          break
  </code></pre>
  
  <p>I've tried to optimize the code by reducing the nr of steps required and by using a mathematical formula for triangular numbers. My code works for 5 divisors, but it takes ages to find 500 divisors. I've let the code run for 3 hours yesterday and still no output. Should I let the code run for more than 3 hours, or will the output never be printed as there is something wrong with my code?</p>