In case you missed the announcement: The Alteryx One Fall Release is here! Learn more about the new features and capabilities here
ACT NOW: The Alteryx team will be retiring support for Community account recovery and Community email-change requests after December 31, 2025. Set up your security questions now so you can recover your account anytime, just log out and back in to get started. Learn more here
Start Free Trial

General Discussions

Discuss any topics that are not product-specific here.

Euleryx Project 12 – Highly Divisible Triangular Numbers

Pilsner
13 - Pulsar

Euleryx Problem 12 – Highly Divisible Triangular Numbers

pilsworthbuliencom_0-1760617671489.png

 

My workflow and macros:

 

Spoiler

pilsworthbuliencom_1-1760617671491.png

 

Macro1:

pilsworthbuliencom_23-1760617747523.png

Macro2:

pilsworthbuliencom_24-1760617791989.png

 



Answer: 76576500



Last Week's Favourite Solution:
Many weird and wonderful solutions from last week made it another tough call. The solutions that stood out most were those which were able to arrive at a solution without having to create 4 separate streams. In particular, @DaisukeTsuchiya's method of creating a list to determine the potential adjustments to each number's coordinates needed, then appending this onto the main data stream, stood out for its simple yet streamlined nature. Please find this solution on page one of last week's post or click here.

 

Definitions:

  • Triangular Numbers: A triangular number is a number that can be represented by a pattern of dots arranged in a triangle.

pilsworthbuliencom_2-1760617671492.png

 

 

 

  • Coprime: Two or more numbers are considered coprime if their only common positive factor is one.

 

  • Basic property of divisibility:

    Let's say we have 3 numbers, such as a, b and c – where:

                                                                 a x b = c

 

               Now, let's introduce another number k.

              Consider the case where a is divisible by k.

 

              Based on the first formula, we can say that (as a x b = c) c is divisible by a.

 

              As a is divisible by k, and c is divisible by a. c is also divisible by k. In other words, all factors of a, are also factors of c.

 

 

Mathematical Theory:

Two things to note before we begin. Firstly, my workflow took over 9 minutes to run, so based on the one-minute target set by Project Euler, I have technically failed ☹️. With that being said, we’d love to hear how you get on, so feel free to include the run time in your reply. Secondly, despite what the run time may suggest, this is by far the most technical post yet. I hope you're ready!

BuckleUpGIF.gif

 



 

 

Step 1 How to calculate a Triangular Number:

As stated in the definitions, a triangular number is a number that can be represented by a pattern of dots arranged in a triangle, with the first triangular number being 1. To keep the “triangular shape”, to get the second number, we must put 2 more dots on the bottom. Hence, the second triangular number is 3 (1 + 2).

 

The third triangular number requires 3 more dots to be added to the bottom, taking the value up to 6 (1 + 2 + 3). The next few triangular numbers are as follows:

  • 4th triangular number: 1 + 2 + 3 + 4  = 10
  • 5th triangular number: 1 + 2 + 3 + 4 + 5  = 15
  • 6th triangular number: 1 + 2 + 3 + 4 + 5 + 6  = 21

 

Hopefully, you can now see a pattern emerging. The “Nth” triangle number is the sum of all the numbers less than or equal to N. The numbers 1….N form an arithmetic sequence and as you may recall from Problem 6, we looked at the Arithmetic Series equation, to help us easily calculate their values.

 

Arithmetic series:

pilsworthbuliencom_4-1760617671574.png

 

Therefore, the Nth triangle number = 0.5 x n x (n + 1).

 

 

Now it's one thing claiming this works, but it's another thing testing it, so let's use the formula to find the 4th, 5th and 6th triangular numbers to see if the answers match.

  • 4th triangular number: 0.5 x 4 x 5  = 2 x 5 = 10
  • 5th triangular number: 0.5 x 5 x 6  = 5 x 3 = 15
  • 6th triangular number: 0.5 x 6 x 7  =  3 x 7 = 21

Now we know that the Nth triangle number = 0.5 x n x (n + 1), we can use the basic property of divisibility to help us.

 

Step 2 Examining the triangle number formula:

In order to apply the basic rule of divisibility, we must have integer (whole number) values only. Because the formula divides by 2, we need to make sure the result is always a whole number before we can use the divisibility rule.

 

GreenhairbilSusDogGIF.gif

 

As we know, an integer is either even or odd, so let's check both cases.

 

N Is even:

If n is even, we can express it as follows: n = 2m, where m is any whole number

 

In this case, the formula becomes:

pilsworthbuliencom_6-1760617671715.png

 

 

m and (2m+1) are both integer values, so for even numbers, we can apply the basic rule of divisibility.

 

N Is odd:

If n is odd, we can express it as follows: n = 2m + 1, where m is any whole number

The formula can then be expressed as follows:

 

pilsworthbuliencom_7-1760617671715.png

 

 

Similarly to before, we now have two whole numbers multiples together, (2m+1) and (m+1), therefore we can apply the basic rule of divisibility.

 

So, what we have proven?

 

No matter weather n is even or odd, the triangular number formula always contains two whole numbers multiplied by each other.

 

From this point forward, we will discuss the case where n is even only meaning n/2 and (n + 1) are both integers:

 

pilsworthbuliencom_8-1760617671715.png

 

 All the work applies in the same way for the cases where n is odd.

 

Step 3 Applying the basic rule of divisibility:

 

As we now know that n/2 and (n+1) are both integers, we can apply the basic rule of divisibility. All factors of n/2 and all factors of (n+1) are also factors of the nth triangle number

pilsworthbuliencom_9-1760617671715.png

 

 

As all factors of n/2 and (n+1) are also factors of Tn, they must also have all the same prime factors. So if we can list all the prime factors of n/2 and (n+1) we will have found all the prime factors of Tn.

 

 

SoWhatAlBundyGIF.gif

 

But why is this helpful? Well, we can actually find out the number of factors a number has by using its prime factors. The formula that helps us do this is often called, divisor function formula. It works as follows:

If a number n has a prime factorisation:

pilsworthbuliencom_11-1760617671807.png

 

Then the total number of factors of n is given by:

pilsworthbuliencom_12-1760617671808.png

 

 

To take an example. The number 60 has the following prime factorisation:

pilsworthbuliencom_13-1760617671808.png

 

As you can see, the 2 is squared, but the 3 and the 5 are just to the power of 1. Therefore, 6 must have the following number of factors.

 

pilsworthbuliencom_25-1760618365060.png= 12

 

By finding all the prime factors of n/2 and (n+1) we can then apply the formula. We don’t need to worry about n/2 or (n+1) sharing any prime factors, as they are coprime. (any two adjacent numbers are coprime). By applying the formula we know if we have reached the 500 factor minimum threshold. If not, we need to look at a different number.

 

Method:

1) Enter your starting value. I decided to play it safe and begin searching at the 500th triangular number
pilsworthbuliencom_15-1760617671808.png

 

2) Feed the data into an iterative macro, and configure it display to the minimum number of required factors.
pilsworthbuliencom_16-1760617671811.png

 


3) Inside the first macro, we calculate both n and (n+1). Then divide the even value by two and feed both numbers into the macro we created back in problem 5, which lists all the prime factors. (The reason for doing this is explained in the theory section above)

pilsworthbuliencom_17-1760617671812.png

 


4) Now that we have all the prime numbers listed, we have to find the number of times each prime number appears.

pilsworthbuliencom_18-1760617671814.png

 





5) Now, to actually implement the formula, we must add one to each of these counts (powers) and multiply them all together.

pilsworthbuliencom_19-1760617671816.png

 


6) Finally, we must filter to see if the value was over 500, and if it is now, we must add one to the nth triangular number value.

pilsworthbuliencom_20-1760617671818.png


7) Running the above as an iterative, will eventually tell you which term is the first triangular number with over 500 factors. All that’s left to do is implement the formula to find its actual value.

pilsworthbuliencom_21-1760617671819.png

 


8) Submit your answer to the Project Euler Website!

 

 

BabyBossDanceGifGIF.gif

 



Summary:

Combining what we previously learnt about series, as well as utilising the Divisor Function Formula, we were able to figure out which term the answer was on, before even computing the value of any triangular numbers themselves.

 

Want to find out more, follow this link to our introduction post - Euleryx: Let The Games Begin.

10 REPLIES 10
Hub119
12 - Quasar
12 - Quasar

This was the first one I had to go learn some math for... I like how even with the quicker problems these force you to learn the math tricks.  No need to dive into too much of a detailed description though it appears as @Pilsner already has us covered.

Spoiler
Main WorkflowMain Workflow
Spoiler
Recycled Factor MacroRecycled Factor Macro
Pilsner
13 - Pulsar

@Hub119 , that's very clever. I didn't think of finding the factors for all the numbers at once, but it's SO much quicker 😄

Carolyn
12 - Quasar
12 - Quasar

I went with a more brute force solution but it ran in 7.6 seconds :D 

 

I generated all the numbers 1 to 15k and then did a Multi-Row to get the triangle maths. I skipped the first 10k values, because they probably weren't my answer (I can't remember if there were multiple skip first x values or if I just did 10k and hoped for the best). Then I fed the triangle sums into my previously developed macro which finds all the factors of a number. It has 2 outputs - 1 shows the list of factors and the other does a distinct count of all the factors - that's the one that I used here. Then I just filtered for where the Count > 500 and found the lowest. 

 

 

Spoiler
2025-10-16 10_02_25-Alteryx Designer x64 - _Euler_012_Carolyn.yxmd.png

2025-10-16 10_09_24-Alteryx Designer x64 - _Euler_012_Carolyn.yxmd.png

 

 

Qiu
21 - Polaris
21 - Polaris

@Pilsner 
I referred the Coprime property below and solved this one.
But I will read through your note before I post mine 😁. Thanks a lot. 
https://martin-ueding.de/posts/project-euler-solution-12-highly-divisible-triangular-number/

patrick_digan
17 - Castor
17 - Castor

Team Brute Force

Spoiler
I generated the first 15k numbers, then found all the divisors <= Square Root. Then I counted the divisors, multiplied by 2 (since I only went to the square root, I was missing the other half), and found the first one to have more than 500. It took 2 minutes on my not very powerful machine.
patrick_digan_0-1760700830528.png

 

CoG
14 - Magnetar

Nicely done, @Pilsner! The coprime component of this problem is a very useful insight. I utilized the same fact, but via... String Coding! I optimized my factorizing Generate Rows code

 

Spoiler
Screenshot 0012-1.png

As was mentioned in the OP, I could have added another formula tool to half the even values prior to Searching for Factors, but this workflow processes 15,000 records in 1.4 seconds, which wouldn't change much at all, and I wanted to shave off a tool.

Still loving going through these problems!

AkimasaKajitani
17 - Castor
17 - Castor

Team brute force!

 

Spoiler
AkimasaKajitani_0-1760753230722.png

 

DaisukeTsuchiya
14 - Magnetar
14 - Magnetar

I solved it with a brute-force approach. 

Spoiler
I used 'Generate Rows' and 'Multi-Row Formula' to get the triangular numbers, then found the answer via prime factorization. The processing time was 12 seconds.

スクリーンショット 2025-10-20 100209.jpgスクリーンショット 2025-10-20 100234.jpgスクリーンショット 2025-10-20 100252.jpg

 

Qiu
21 - Polaris
21 - Polaris

Here is my take.

Spoiler
Euleryx Project 12A.png
Labels
Top Solution Authors