projecteuler.net problem #12: triangle # with 500+ divisors
Posted: Sat Oct 10, 2009 6:01 pm
I’m trying to learn some PHP so I embarked on Project Euler. So far it has been something in between jolly good fun and having tendencies to gobble up a live goat out of frustration.
I’ve worked my way up to problem 12, and the solution I’ve created is way too slow (beyond waiting for it to finish slow), so I was hoping some more advanced coders could help me clean and speed it up: here’s the code on pastie.org the in the pastie should be
This is the problem statement:
I’ve worked my way up to problem 12, and the solution I’ve created is way too slow (beyond waiting for it to finish slow), so I was hoping some more advanced coders could help me clean and speed it up: here’s the code on pastie.org the
Code: Select all
while ($delers < 500) {Code: Select all
while ($delers < 501) {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:
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?