62 lines
3.2 KiB
Plaintext
62 lines
3.2 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "fdd3f4eb",
|
|
"metadata": {},
|
|
"source": [
|
|
"# [Multiples of 3 or 5](https://projecteuler.net/problem=1)\n",
|
|
"\n",
|
|
"Lots of different approaches to this problem! Writing a program may be the easiest, but I always find it interesting when these problems can be solved without a computer doing the heavy lifting, and with a little bit of [summation](https://en.wikipedia.org/wiki/Summation) knowledge and the [inclusion-exclusion principle](https://en.wikipedia.org/wiki/Inclusion%E2%80%93exclusion_principle), we can calculate this answer by hand.\n",
|
|
"\n",
|
|
"First off, the sum of the multiples of 3 below 1000 is\n",
|
|
"$$3 + 6 + 9 + \\cdots + 999$$\n",
|
|
"Likewise, the sum of the multiples of 5 below 1000 is\n",
|
|
"$$5 + 10 + 15 + \\cdots + 995$$\n",
|
|
"Although these sums may seem tedious to calculate by hand, we can apply the distributive property and factor out the 3 and 5, respectively, from each summation.\n",
|
|
"$$\\begin{align}\n",
|
|
"3 + 6 + 9 + \\cdots + 999 &= 3(1 + 2 + 3 + \\cdots + 333) \\\\\n",
|
|
"5 + 10 + 15 + \\cdots + 995 &= 5(1 + 2 + 3 + \\cdots + 199)\n",
|
|
"\\end{align}$$\n",
|
|
"We are then left with a summation of the form\n",
|
|
"$$1 + 2 + 3 + \\cdots + n$$\n",
|
|
"in both instances. If we successively evaluate this summation at $n = 1,2,3,\\ldots$ we get the [triangular numbers](https://en.wikipedia.org/wiki/Triangular_number), which have a well-known closed formula:\n",
|
|
"$$1 + 2 + 3 + \\cdots + n = \\frac{n(n+1)}{2}$$\n",
|
|
"(This formula can be proven valid with [mathematical induction](https://en.wikipedia.org/wiki/Mathematical_induction), but you don't need to formally prove it to gain an intuition for it. Click the link on triangular numbers to find other explanations.)\n",
|
|
"\n",
|
|
"Therefore, the first summation equals $3(333(334)/2) = 166833$, and the second equals $5(199(200)/2) = 99500$.\n",
|
|
"\n",
|
|
"However, we can't just sum these two values. That's because any number that's a multiple of both 3 and 5 is included in *both* of these summations, so if we add the results up, we'll count those values twice! To adjust for this, we'll need to subtract the sum of those numbers from our total so they are only counted once. Luckily, a number is a multiple of both 3 and 5 if and only if it is a multiple of 15, so we can apply our triangular number formula from above.\n",
|
|
"$$15 + 30 + 45 + \\cdots + 990 = 15(1 + 2 + 3 + \\cdots + 66) = 15(66(67)/2) = 33165$$\n",
|
|
"\n",
|
|
"Our answer is then\n",
|
|
"$$(3 + 6 + 9 + \\cdots + 999) + (5 + 10 + 15 + \\cdots + 995) - (15 + 30 + 45 + \\cdots + 990) = 233168$$\n",
|
|
"\n",
|
|
"## Relevant sequences\n",
|
|
"* Triangular numbers: [A000217](https://oeis.org/A000217)"
|
|
]
|
|
}
|
|
],
|
|
"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
|
|
}
|