75 lines
3.6 KiB
Plaintext
75 lines
3.6 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "088fe896",
|
|
"metadata": {},
|
|
"source": [
|
|
"# [Smallest Multiple](https://projecteuler.net/problem=5)\n",
|
|
"\n",
|
|
"Another problem we can solve by hand! We're looking for the [least common multiple](https://en.wikipedia.org/wiki/Least_common_multiple), or LCM, of all the numbers from 1 to 20. Obviously,\n",
|
|
"$$20! = 20 \\times 19 \\times 18 \\times \\cdots \\times 1 = 2432902008176640000$$\n",
|
|
"is *a* common multiple, but the LCM is indeed smaller than this.\n",
|
|
"\n",
|
|
"One way to find the LCM is to first determine the prime factorizations of these numbers.\n",
|
|
"* $1 = 1$\n",
|
|
"* $2 = 2$\n",
|
|
"* $3 = 3$\n",
|
|
"* $4 = 2^2$\n",
|
|
"* $5 = 5$\n",
|
|
"* $6 = 2 \\times 3$\n",
|
|
"* $7 = 7$\n",
|
|
"* $8 = 2^3$\n",
|
|
"* $9 = 3^2$\n",
|
|
"* $10 = 2 \\times 5$\n",
|
|
"* $11 = 11$\n",
|
|
"* $12 = 2^2 \\times 3$\n",
|
|
"* $13 = 13$\n",
|
|
"* $14 = 2 \\times 7$\n",
|
|
"* $15 = 3 \\times 5$\n",
|
|
"* $16 = 2^4$\n",
|
|
"* $17 = 17$\n",
|
|
"* $18 = 2 \\times 3^2$\n",
|
|
"* $19 = 19$\n",
|
|
"* $20 = 2^2 \\times 5$\n",
|
|
"\n",
|
|
"Now, for each prime factor that appears in these factorizations, we'll take note of the largest power they're raised to. For instance, $2^4$ (the prime factorization of 16) is the largest power of 2 appearing.\n",
|
|
"\n",
|
|
"The LCM is the product of all these \"largest prime powers.\"\n",
|
|
"$$2^4 \\times 3^2 \\times 5 \\times 7 \\times 11 \\times 13 \\times 17 \\times 19 = 232792560$$\n",
|
|
"How do we know this is the LCM? Well, it's trivial to see it is *a* common multiple - just divide by each of the above numbers to confirm. Furthermore, we know it's the *least* common multiple because if we divided by any of these prime factors to get a smaller result, it would no longer be divisible by one or more of our numbers. For instance, if we divide by 3, our result is no longer divisible by $9 = 3^2$ or $18 = 2 \\times 3^2$.\n",
|
|
"\n",
|
|
"## Alternate method\n",
|
|
"I personally find the prime factorization method above the easiest way to solve this specific problem by hand. However, if there were a lot more numbers or the numbers were larger, I wouldn't want to do all those factorizations. Fortunately, there is another method that doesn't involve factoring at all, and can be implemented efficiently on a computer.\n",
|
|
"\n",
|
|
"For two numbers $m$ and $n$,\n",
|
|
"$$\\mathrm{lcm}(m,n) = \\frac{mn}{\\gcd(m,n)}$$\n",
|
|
"where $\\gcd$ is the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor). The [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm) gives an efficient method for calculating the GCD.\n",
|
|
"\n",
|
|
"This formula is only defined for two numbers, but if we want to find an LCM of a set of three or more numbers, we can simply find the LCM of any two numbers in the set, then proceed to find the LCM of that value and another number from the set, repeating until we have used each number. For example, to find the LCM of 5, 8, and 14, you can first find the LCM of 5 and 8 using the above formula (40), then find the LCM of 40 and 14 (280)."
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "SageMath 9.5",
|
|
"language": "sage",
|
|
"name": "sagemath"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.11.2"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|