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?
SCJP
Visit my download page
SCJP
Visit my download page
Randall Twede wrote:i want to start the outer loop at a much bigger number than 496
it takes a long time starting at 1(or 496) and many "small" numbers cannot possibly have 500 factors
i guess what i wish i knew is: what is the largest number(triangular or otherwise) that cannot possibly have over 500 factors?
SCJP
Visit my download page
There are an infinite number of prime numbers which have much fewer than 500 factors.Randall Twede wrote: . . . i guess what i wish i knew is: what is the largest number(triangular or otherwise) that cannot possibly have over 500 factors?
Jeff Verdegan wrote:
i guess what i wish i knew is: what is the largest number(triangular or otherwise) that cannot possibly have over 500 factors?
That seems to go against the spirit of the problem.
Are you making use of the fact that the sum of the the integers 1..N is N * (N + 1) / 2 ? That may or may not help the factorization.
Paul Clapham wrote:
Jeff Verdegan wrote:
i guess what i wish i knew is: what is the largest number(triangular or otherwise) that cannot possibly have over 500 factors?
That seems to go against the spirit of the problem.
You mean that using math in advance to reduce the amount of work necessary is a bad thing? (For that particular question: there are arbitrarily large numbers that have only 2 factors -- namely prime numbers.)
SCJP
Visit my download page
SCJP
Visit my download page
SCJP
Visit my download page
SCJP
Visit my download page
Randall Twede wrote:i * i <= number doesnt work
take 16 for example the sqrt is 4 but it also has 8 and 16 as factors
Dennis Deems wrote:Yes, but you can make use of the fact that factors come in complementary pairs.
Campbell Ritchie wrote:It is also worth running from 2 to √n inclusive
"Dennis Deems" wrote:make use of the fact that factors come in complementary pairs
"Paul Clappham" wrote:Except when the number being factorized is a perfect square
Steve
Randall Twede wrote:i * i <= number doesnt work
take 16 for example the sqrt is 4 but it also has 8 and 16 as factors
Randall Twede wrote:i might try going back to !(i > number / 2)
and change if(factors > 500) to if(factors > 499) to account for the number itself being a factor.
if i wait long enough i might get the correct answer. then i can go to the forum for this problem and see how others solved it
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
SCJP
Visit my download page
SCJP
Visit my download page
Steve
You are the 59999th person to have solved this problem.
Martin Vajsar wrote:1) Obtain prime factors. This is much faster, since you can use a list of primes (either precomputed, or created on the fly) to do division tests. After each prime factor found the remaining number is diminished, which also speeds things up greatly.
2) Compute the number of all factors which can be obtained from the list of prime factors. The good thing is you don't have to materialize the factors, which is a great time saver, you need just the number. I cheated and looked this up, though it is so clear that I feel greatly ashamed I didn't figure this out on my own. Drat!
Their achilles heel is the noogie! Give them noogies tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|