title: Triangle numbers problem....show within 4 seconds
body: <blockquote>
    <p>The sequence of triangle numbers is
    generated by adding the natural
    numbers. So the 7th triangle number
    would be 1 + 2 + 3 + 4 + 5 + 6 + 7 =
    28. The first ten terms would be:</p>
    
    <p>1, 3, 6, 10, 15, 21, 28, 36, 45, 55,
    ...</p>
    
    <p>Let us list the factors of the first
    seven triangle numbers:</p>
  
  <pre><code> 1: 1
   3: 1,3
   6: 1,2,3,6
  10: 1,2,5,10
  15: 1,3,5,15
  21: 1,3,7,21
  28: 1,2,4,7,14,28
  </code></pre>
    
    <p>We can see that 28 is the first
    triangle number to have over five
    divisors.</p>
    
    <p>Given an integer n, display the first
    triangle number having at least n
    divisors.</p>
    
    <p>Sample Input: 5</p>
    
    <p>Output 28</p>
    
    <p>Input Constraints: 1&lt;=n&lt;=320</p>
  </blockquote>
  
  <p>I was obviously able to do this question, but I used a naive algorithm:</p>
  
  <ol>
  <li><p>Get <em>n</em>.</p></li>
  <li><p>Find triangle numbers and check their number of factors using the mod operator.</p></li>
  </ol>
  
  <p>But the challenge was to show the output within 4 seconds of input. On high inputs like 190 and above it took almost 15-16 seconds. Then I tried to put the triangle numbers and their number of factors in a 2d array first and then get the input from the user and search the array. But somehow I couldn't do it: I got a lot of processor faults. Please try doing it with this method and paste the code. Or if there are any better ways, please tell me.</p>