We are celebrating the 10-year anniversary of the Alteryx Community! Learn more and join in on the fun here.
Start Free Trial

General Discussions

Discuss any topics that are not product-specific here.

Euleryx Project 5 - Smallest Multiple

Pilsner
13 - Pulsar

Euleryx Problem 5 - Smallest Multiple

q.png

 

My workflow and answer:

Spoiler

Pilsner_0-1756384534094.png

Answer: 232792560

 


Last Weeks Favourite Solution:
There are already some very clever solutions to last weeks challenges, they have highlighted how sometimes making an educated assumption can drastically reduce to workload. This week, our favourite solution award goes to @Yoshiro_Fujimori. By flipping the problem on its head, and creating a descending list of palindromic numbers as the starting point, @Yoshiro_Fujimori's solution was incredibly efficient and even found the answer to the problem with 4 digit numbers. Find this solution on page 1 of last week post, or click here.

 

Definitions:

  • Evenly Divisible: Despite the misleading name, this does not mean divisible by an even number. What this actually means is, divisible without a remainder or decimal.

 

Mathematical Theory:

 

This problem is effectively asking us to find the Lowest Common Multiple (LCM) of all the numbers 1-20. With this in mind, we can use a method often referred to as the LCM by prime factorisation. So, what does this mean?  

 

Let's begin with the prime factorisation part. As we have seen before (in Problem 3), the Fundamental Theorem of Arithmetic states that all numbers can be factorised into prime numbers. We also saw how to do this using a factor tree.

 

Pilsner_1-1756384534172.png

 

 

From this point forward, we will use the numbers 30 and 28 as examples and for those who have forgotten, here are some factor trees and the prime factors for these numbers.



Pilsner_13-1756384908607.png


Prime factors 30 = 2 x 3 x 5

Prime factors 28 = 2 x 2 x 7

 

Now that we have the prime factors, we can use them to find the LCM. The rule here is to take the highest power, of each prime and multiply them all together. So, in this example:

 

  • 30 = 2 x 3 x 5
  • 28 = 2 x 2  x 7

The unique prime numbers here are 2, 3, 5 and 7. Let's find the highest power for them all:

  • For 2: 2 x 2
  • For 3: 3
  • For 5: 5
  • For 7: 7



Or if you want to do this pictographically, use a Venn diagram:

Pilsner_4-1756384534174.png

 

 

By taking this list of numbers (either from the Venn diagram or the list of highest powers) we come up with the following expression:

 

2 x 2 x 3 x 5 x 7 = 420

 

Therefore, the LCM of 30 and 28 is 420.

 

 

Applying this method to the problem at hand, if we find all the prime factors of the numbers from 1 – 20, then create a list of each one's highest power, we should arrive at a solution.

 

 

Method:

 

As hinted at above, this method leverages the iterative macro created for Problem 3. For this problem, I will just refer to it as the List of Prime Factors macro, but if you want a more detailed explanation, please look back at Problem 3.


  1. This process begins with generating our data (numbers 1 – 20) and setting up some columns ready for our iterative macro. In this case we need out starting number to be static, a column which can be populated with our list of primes, and another Number column to update each iteration.
    Pilsner_5-1756384534175.png
  2. Feed the input into the List of Prime factors macro to get the following output.

    Pilsner_6-1756384534176.png
  3. We need to figure out the power of each prime factor, per starting number. The first step here would be to separate out the list of prime factors into separate rows, based on the comma delimiter.
    Pilsner_7-1756384534176.png

  4. Count the number of times each prime number appears as a prime factor, per starting number. (This is effectively finding the power of each prime factor).

    Pilsner_8-1756384534177.png

  5. For each prime number, find its highest power. (Remember count = power)
    Pilsner_9-1756384534178.png

  6. Calculate the value of each prime when its highest power is applied.
    Pilsner_10-1756384534179.png

  7. Multiply all the values you have just calculated together to get your answer.

    Pilsner_11-1756384534181.png

  8. Upload your answer to the Project Euler Website!
    CheckedOutGIF.gif

 

Summary:

Although the question didn’t explicitly state this, the trick we used was to recognise that it was asking for the Lowest Common Multiple. Armed with this idea, we were once again able to utilise the Fundamental Theorem of Arithmetic to find to LCM via prime factorisation.

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

11 REPLIES 11
Carolyn
12 - Quasar
12 - Quasar

Solved!

 

I knew with this one that I needed to find the prime factors for each number. Then I needed to find the maximum needed value of each prime factor (e.g. 20 = 2 * 2 * 5, so I need one 5 and two 2s --> repeat for every number) to get the LCM.

 

I used my prime factor macro from #3 to prime factor (that's a verb) every number. I was very happy when I was able to reuse the macro already. Once I had that, I found the maximum number of 2's and 3's, etc that I needed, and multipled those together. 

 

Spoiler
2025-08-28 10_09_42-Alteryx Designer x64 - Euler_005_Carolyn_1.yxmd.png

 

Qiu
21 - Polaris
21 - Polaris

It is similar with you guys approach, use the product of prime number under 20, then multiply, 2, 2,2 (for 16), 3 (for 9), that will be our largest number.

Spoiler
Euleryx Project 4.jpg
Yoshiro_Fujimori
15 - Aurora
15 - Aurora

My solution.

 

Spoiler
My idea is that if I divide each number from 1 to the end when it is evenly dividable, I would get the list of prime factors of the number I need to answer.
For example, from 1 to 10 each number would be processed as below;
Euleryx_5_iterationImage.png
The product of 1*2*3*2*5*1*7*2*3*1 = 2520.

Workflow

Euleryx_5_workflow.png
Note
    If I use a newer version, just Summarize Tool would calculate the Product.
    Because I use Designer 2022.3, Summarize Tool does not support Product,
    I have to use Exp([Sum of Log()]) as an alternative.
    This method works only when the answer is less than 15 digits (i.e. the precision of "Double" data type).

Iterative Macro

Euleryx_5_macro.png

 

 

PangHC
13 - Pulsar

Do i consider cheat? 🤣

I built one LCM macro when Advent of code, it got 1 year keep asking about LCM. 

 

explanation

 

Spoiler
mainly repeat count for both formula. 
LCM = (a * b) / gcd(a, b)

gcd  = if mod(a,b) = 0 then b else repeat mod(b,mod(a,b)) endif


Screenshot 2025-08-29 100303.png

 

gawa
16 - Nebula
16 - Nebula

No Macro solution with the Generate Row + Multi Row Formula!

 

Spoiler
I checked LCM in turn from 1 to 20 by using Multi Row Formula.
LCM (1, 2) = 2
LCM(LCM(1, 2), 3) = LCM(2, 3) =6
LCM(LCM(LCM(1, 2), 3), 4) = LCM(6, 4) = 12
.....

image.png
DaisukeTsuchiya
14 - Magnetar
14 - Magnetar

Done

Spoiler
I calculated the prime numbers and prime factors up to 20 then got LCM.
It's inspiring to see everyone solving the problems so simply!

スクリーンショット 2025-08-30 112055.jpgスクリーンショット 2025-08-30 112118.jpg
AkimasaKajitani
17 - Castor
17 - Castor

My solution!

 

A simple brute force approach. I use the Message tool to stop the workflow earlier.

 

Spoiler
image.png
martinson
11 - Bolide

Wow, took me a while to remember that prime factors exist! Great challenge @Pilsner. Can't wait to see the ingenious solutions the rest of you have no doubt created!

Spoiler
martinson_0-1756830044617.png
martinson_1-1756830059046.png

 

martinson_2-1756830073580.png

Time: 1 hour 8 minutes



Cheers,
martinson

LinkedIN

Bulien
Pilsner
13 - Pulsar

@Carolyn , it may be the first, but like you suggested before, I don't think it will be the last time your prime number macro will come in useful 😄


@AkimasaKajitani I have never even seen the message tool used like this before, it's genius!

Labels
Top Solution Authors