53 lines
2.0 KiB
Plaintext
53 lines
2.0 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "a39ba505",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Sum Square Difference\n",
|
|
"> The sum of the squares of the first ten natural numbers is,\n",
|
|
"> $$1^2 + 2^2 + \\cdots + 10^2 = 385$$\n",
|
|
"> The square of the sum of the first ten natural numbers is,\n",
|
|
"> $$(1 + 2 + \\cdots + 10)^2 = 55^2 = 3025$$\n",
|
|
"> Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is $3025 - 385 = 2640$.\n",
|
|
"> \n",
|
|
"> Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.\n",
|
|
"\n",
|
|
"In [problem 1](https://projecteuler.net/problem=1), we applied the following formula for [triangular numbers](https://en.wikipedia.org/wiki/Triangular_number):\n",
|
|
"$$\\sum_{k=1}^n k = \\frac{n(n+1)}{2}$$\n",
|
|
"We can apply it again here and determine that\n",
|
|
"$$(1 + 2 + 3 + \\cdots + 100)^2 = \\left(\\frac{100(101)}{2}\\right)^2 = 25502500$$\n",
|
|
"\n",
|
|
"A similar formula exists for computing [sums of squares](https://en.wikipedia.org/wiki/Square_pyramidal_number):\n",
|
|
"$$\\sum_{k=1}^n k^2 = \\frac{n(n+1)(2n+1)}{6}$$\n",
|
|
"(In fact, [Faulhaber's formula](https://en.wikipedia.org/wiki/Faulhaber%27s_formula) gives a formula for the sum of $k$th powers, but we obviously only need the cases $k=1$ and $k=2$ for this problem.) Consequently,\n",
|
|
"$$1^2 + 2^2 + 3^2 + \\cdots + 100^2 = \\frac{100(101)(201)}{6} = 338350$$\n",
|
|
"\n",
|
|
"Therefore, the difference is $25502500 - 338350 = 25164150$."
|
|
]
|
|
}
|
|
],
|
|
"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
|
|
}
|