From charlesreid1

The question

Triangle numbers are numbers generated by summing the first n integers, i.e., 1 + 2 + 3 + ... + n

The first ten triangle numbers are:

1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...

Let us list the factors of the first seven triangle numbers:

    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

We can see that 28 is the first triangle number to have over five divisors.

What is the value of the first triangle number to have over five hundred divisors?


This one is trivial if you implement the formula

You also need a method to count divisors up to sqrt(N), and double that number to yield the total number of factors. You could use a prime number sieve here like the Sieve of Eratosthenes, or just implement a for loop to check for factors using the modulus operator. The highest number you'll need to check the divisibility of is about 8 digits, so you perform the factor check for numbers up to around 12,000.