Euler Project: Problem No .12


Although Euler Project  questions are designed to be solved sequentially. I wasn’t able to hold myself from giving it a try when I saw some of my roommates trying out this problem.

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?

I tried out the above problem and got myself a  solution using two basic rules from mathematics.

  1. The nth triangular number can easily be obtained as : (n * n-1) / 2
  2. If a number ” n ” can be written as a multiple of two consecutive numbers “p”  and “q” ie:  if n = p * q then number of factors of n = number of factors of p * number of factors of q – 1

My Solution is available at my git-hub id:

git@github.com:rohitnjan88/Euler-problems-in-Python.git

My solution clocked below 1 seconds.(  0.244 seconds to be exact ) .

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: