Skip to content

Latest commit

 

History

History

problem12

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Problem 12: Highly divisible triangular number

Problem statement

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?

Comments

Again, I've had to take too long between these problems, so I've been thinking about this one. I think what I'll do is develop a seive-like structure to find the powers of different primes that go into different numbers, and then look for a number such that n*(n-1)/2 has more than five hundred divisors. (then the answer is n*(n-1)/2))

Given that a number is p1^n1 * p2^n2 * ... * pk^nk, then it has (n1+1)*(n2+1)*...*(nk+1) divisors.

This will probably involve using the itertools crate for the fold1 function, so that's something new.

...

As predicted, I used fold1. As might not be too surprising, I also hit my head against integer type mixups here too.

I am getting into some type issues that I don'[t understand - in this problem I wound up using a &mut [&mut [u8]], which looks a bit strange to me and I don't know what's going on there with that. (but it was what the compiler asked me to use, so...)

Source

Source code