The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be .
The first ten terms would be:
Let us list the factors of the first seven triangle numbers:
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?
Actually we don’t need this. If we refer back to Problem 1, we can generalize any term in an arithmetic series
and that means for triangle numbers:
Number of Factors
The naive approach to finding how many factors a number has is to trial divide the number, , by numbers from to .
This method is actually too slow for us to use to brute force an answer. We can use some information from Problem 5 to help us. We learned that any number can be decomposed using prime numbers.
It is also true that any number, , that is a power of a prime, , , will have factors. For example:
Now consider a number that is composed of multiple primes:
The number of total divisors can be determined by the powers of the prime decomposition using the rule of product, so will have:
Brute Force
Optimizations
Each triangle number we are checking, when being factored is re generating the primes that it needs to check. Let’s try pre-generating a list of prime numbers.
Let’s try not using our prime factor function and count the number of divisors as we go.
Math
Looking again at the generalization for the triangle numbers
we can use the fact that and are co-prime, meaning they do not share any common prime factors. Because of this, we can generalize the number of total divisors for a triangle number as: