various edits, including just linking to the problem instead of copying
This commit is contained in:
parent
b80145e70e
commit
4eef99dfce
|
@ -5,10 +5,7 @@
|
|||
"id": "fdd3f4eb",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Multiples of 3 or 5\n",
|
||||
"> If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6, and 9. The sum of these multiples is 23.\n",
|
||||
">\n",
|
||||
"> Find the sum of all the multiples of 3 or 5 below 1000.\n",
|
||||
"# [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",
|
||||
|
@ -33,7 +30,10 @@
|
|||
"$$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$$"
|
||||
"$$(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)"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
|
|
@ -5,10 +5,7 @@
|
|||
"id": "1899e933",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Even Fibonacci Numbers\n",
|
||||
"> Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first terms will be:\n",
|
||||
"> $$1, 2, 3, 5, 8, 13, 21, 34, 55, 89, \\ldots$$\n",
|
||||
"> By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.\n",
|
||||
"# [Even Fibonacci Numbers](https://projecteuler.net/problem=2)\n",
|
||||
"\n",
|
||||
"There's a lot to learn about the [Fibonacci numbers](https://en.wikipedia.org/wiki/Fibonacci_sequence), and this will not be the last time we see them in a Project Euler problem, but for now this problem keeps it relatively simple.\n",
|
||||
"\n",
|
||||
|
@ -58,6 +55,16 @@
|
|||
" yield a\n",
|
||||
" a, b = b, a + b"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "b3293a7d",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Relevant sequences\n",
|
||||
"* Fibonacci numbers: [A000045](https://oeis.org/A000045)\n",
|
||||
"* Partial sums of even Fibonacci numbers: [A099919](https://oeis.org/A099919)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
|
|
@ -5,10 +5,7 @@
|
|||
"id": "1a8d8609",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Largest Prime Factor\n",
|
||||
"> The prime factors of 13195 are 5, 7, 13, and 29.\n",
|
||||
"> \n",
|
||||
"> What is the largest prime factor of the number 600851475143?\n",
|
||||
"# [Largest Prime Factor](https://projecteuler.net/problem=3)\n",
|
||||
"\n",
|
||||
"The [fundamental theorem of arithmetic](https://en.wikipedia.org/wiki/Fundamental_theorem_of_arithmetic) says that every integer greater than 1 has a unique prime factorization.\n",
|
||||
"\n",
|
||||
|
@ -97,6 +94,15 @@
|
|||
"source": [
|
||||
"Note that this algorithm gives us a factor, but not necessarily a *prime* factor. However, we could just repeatedly apply the algorithm until we only have prime factors left. But how do we know when a factor is prime? We'll need a [primality test](https://en.wikipedia.org/wiki/Primality_test) like the Miller-Rabin algorithm - see [problem 7](https://projecteuler.net/problem=7) for a discussion of that algorithm."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "12233560",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Relevant sequences\n",
|
||||
"* Greatest prime factors: [A006530](https://oeis.org/A006530)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
|
|
@ -5,10 +5,7 @@
|
|||
"id": "9c7a281d",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Largest Palindrome Product\n",
|
||||
"> A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is $9009 = 91 \\times 99$.\n",
|
||||
">\n",
|
||||
"> Find the largest palindrome made from the product of two 3-digit numbers.\n",
|
||||
"# [Largest Palindrome Product](https://projecteuler.net/problem=4)\n",
|
||||
"\n",
|
||||
"Our search space is only $\\binom{900}{2} = 404550$ 3-digit pairs - a lot to check by hand but peanuts to a modern computer (we're using notation for [combinations](https://en.wikipedia.org/wiki/Combination) if you're unfamiliar)."
|
||||
]
|
||||
|
|
|
@ -5,10 +5,7 @@
|
|||
"id": "088fe896",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Smallest Multiple\n",
|
||||
"> 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.\n",
|
||||
"> \n",
|
||||
"> What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?\n",
|
||||
"# [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",
|
||||
|
|
|
@ -5,26 +5,23 @@
|
|||
"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",
|
||||
"# [Sum Square Difference](https://projecteuler.net/problem=6)\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",
|
||||
"$$1 + 2 + 3 + \\cdots + n = \\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",
|
||||
"A similar formula exists for computing sums of squares, also called the [square pyramidal numbers](https://en.wikipedia.org/wiki/Square_pyramidal_number):\n",
|
||||
"$$1^2 + 2^2 + 3^2 + \\cdots + n^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$."
|
||||
"Therefore, the difference is $25502500 - 338350 = 25164150$.\n",
|
||||
"\n",
|
||||
"## Relevant sequences\n",
|
||||
"* Triangular numbers: [A000217](https://oeis.org/A000217)\n",
|
||||
"* Square pyramidal numbers: [A000330](https://oeis.org/A000330)"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
|
|
@ -5,10 +5,7 @@
|
|||
"id": "87fa1305",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# 100001st Prime\n",
|
||||
"> By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.\n",
|
||||
">\n",
|
||||
"> What is the 10001st prime number?\n",
|
||||
"# [100001st Prime](https://projecteuler.net/problem=7)\n",
|
||||
"\n",
|
||||
"Unlike integer factorization, we *can* efficiently determine whether a number is prime. One of the simplest and fastest methods is the [Miller-Rabin primality test](https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test), which is a probabilistic test.\n",
|
||||
"\n",
|
||||
|
@ -67,7 +64,7 @@
|
|||
"* Is there an integer $a$ such that $a^n \\not\\equiv a \\pmod{n}$?\n",
|
||||
"* Does 1 have a non-trivial square root modulo $n$?\n",
|
||||
"\n",
|
||||
"If the answer to either of these is yes, then $n$ is *definitely* composite. If both answers are no, this is strong evidence that $n$ is prime, *but not proof*, since we have already demonstrated that both of these conditions can have false positives. A composite number that is erroneously suggested to be prime by these conditions is called a *base $a$ strong pseudoprime*. Fortunately, no number (including Carmichael numbers) is a base $a$ strong pseudoprime for all bases $a$. In fact, Rabin (one of the namesakes of the algorithm) proved that if $n$ is composite, at least 3/4 of the numbers 1 to $n-1$ are witnesses.\n",
|
||||
"If the answer to either of these is yes, then $n$ is *definitely* composite. If both answers are no, this is strong evidence that $n$ is prime, *but not proof*, since we have already demonstrated that both of these conditions can have false positives. A composite number that is erroneously suggested to be prime by both of these conditions is called a *base $a$ strong pseudoprime*. Fortunately, no number (including Carmichael numbers) is a base $a$ strong pseudoprime for all bases $a$. In fact, Rabin (one of the namesakes of the algorithm) proved that if $n$ is composite, at least 3/4 of the numbers 1 to $n-1$ are witnesses.\n",
|
||||
"\n",
|
||||
"Let's finally look at the actual test. Suppose we want to test if an odd number $n$ is prime (testing whether an even number is prime is trivial). There must exist $t \\geq 1$ and odd $u$ such that $n - 1 = 2^t u$."
|
||||
]
|
||||
|
@ -155,6 +152,16 @@
|
|||
" \n",
|
||||
" return True"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "ec384441",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Relevant sequences\n",
|
||||
"* Prime numbers: [A000040](https://oeis.org/A000040)\n",
|
||||
"* Carmichael numbers: [A002997](https://oeis.org/A002997)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
|
|
@ -5,31 +5,7 @@
|
|||
"id": "8744af43",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Largest Product in a Series\n",
|
||||
"> The four adjacent digits in the 1000-digit number that have the greatest product are $9 \\times 9 \\times 8 \\times 9 = 5832$.\n",
|
||||
"> ```\n",
|
||||
"73167176531330624919225119674426574742355349194934\n",
|
||||
"96983520312774506326239578318016984801869478851843\n",
|
||||
"85861560789112949495459501737958331952853208805511\n",
|
||||
"12540698747158523863050715693290963295227443043557\n",
|
||||
"66896648950445244523161731856403098711121722383113\n",
|
||||
"62229893423380308135336276614282806444486645238749\n",
|
||||
"30358907296290491560440772390713810515859307960866\n",
|
||||
"70172427121883998797908792274921901699720888093776\n",
|
||||
"65727333001053367881220235421809751254540594752243\n",
|
||||
"52584907711670556013604839586446706324415722155397\n",
|
||||
"53697817977846174064955149290862569321978468622482\n",
|
||||
"83972241375657056057490261407972968652414535100474\n",
|
||||
"82166370484403199890008895243450658541227588666881\n",
|
||||
"16427171479924442928230863465674813919123162824586\n",
|
||||
"17866458359124566529476545682848912883142607690042\n",
|
||||
"24219022671055626321111109370544217506941658960408\n",
|
||||
"07198403850962455444362981230987879927244284909188\n",
|
||||
"84580156166097919133875499200524063689912560717606\n",
|
||||
"05886116467109405077541002256983155200055935729725\n",
|
||||
"71636269561882670428252483600823257530420752963450\n",
|
||||
"> ```\n",
|
||||
"> Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?\n",
|
||||
"# [Largest Product in a Series](https://projecteuler.net/problem=8)\n",
|
||||
"\n",
|
||||
"First, let's load the number as a tuple."
|
||||
]
|
||||
|
|
|
@ -5,14 +5,7 @@
|
|||
"id": "df906ad5",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Special Pythagorean Triplet\n",
|
||||
"> A Pythagorean triplet is a set of three natural numbers, $a < b < c$, for which, \n",
|
||||
"> $$a^2 + b^2 = c^2$$\n",
|
||||
"> For example, $3^2 + 4^2 = 9 + 16 = 25 = 5^2$.\n",
|
||||
">\n",
|
||||
"> There exists exactly one Pythagorean triplet for which $a + b + c = 1000$.\n",
|
||||
">\n",
|
||||
"> Find the product $abc$.\n",
|
||||
"# [Special Pythagorean Triplet](https://projecteuler.net/problem=9)\n",
|
||||
"\n",
|
||||
"The key mathematical insight for this problem is that Euclid gave a parameterization for generating [Pythagorean triplets](https://en.wikipedia.org/wiki/Pythagorean_triple): given integers $m, n$ such that $m > n > 0$, a triplet is given by\n",
|
||||
"$$\n",
|
||||
|
|
|
@ -5,10 +5,7 @@
|
|||
"id": "ec6f67ee",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Summation of Primes\n",
|
||||
"> The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.\n",
|
||||
">\n",
|
||||
"> Find the sum of all the primes below two million.\n",
|
||||
"# [Summation of Primes](https://projecteuler.net/problem=10)\n",
|
||||
"\n",
|
||||
"Once again, SageMath comes with functions that do the hard part for us."
|
||||
]
|
||||
|
@ -62,6 +59,15 @@
|
|||
" P.add(2)\n",
|
||||
" return P"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "a4a187cf",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Relevant sequences\n",
|
||||
"* Partial sums of primes: [A007504](https://oeis.org/A007504)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
|
|
@ -5,21 +5,7 @@
|
|||
"id": "802ccaa1",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Highly Divisible Triangular Number\n",
|
||||
"> The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be $1+2+3+4+5+6+7=28$. The first ten terms would be:\n",
|
||||
"> $$1,3,6,10,15,21,28,36,45,55,\\ldots$$\n",
|
||||
"> Let us list the factors of the first seven triangle numbers:\n",
|
||||
"> * 1: 1\n",
|
||||
"> * 3: 1,3\n",
|
||||
"> * 6: 1,2,3,6\n",
|
||||
"> * 10: 1,2,5,10\n",
|
||||
"> * 15: 1,3,5,15\n",
|
||||
"> * 21: 1,3,7,21\n",
|
||||
"> * 28: 1,2,4,7,14,28\n",
|
||||
"> \n",
|
||||
"> We can see that 28 is the first triangle number to have over five divisors.\n",
|
||||
">\n",
|
||||
"> What is the value of the first triangle number to have over five hundred divisors?\n",
|
||||
"# [Highly Divisible Triangular Number](https://projecteuler.net/problem=12)\n",
|
||||
"\n",
|
||||
"Yet another problem with a straightforward solution thanks to SageMath's preinstalled functions. We'll also once again apply the closed formula for triangle numbers (see [problem 1](https://projecteuler.net/problem=1))."
|
||||
]
|
||||
|
@ -67,7 +53,12 @@
|
|||
"* $3=3$\n",
|
||||
"* $4=2^2$\n",
|
||||
"* $6=2 \\times 3$\n",
|
||||
"* $12=2^2 \\times 3$\n"
|
||||
"* $12=2^2 \\times 3$\n",
|
||||
"\n",
|
||||
"## Relevant sequences\n",
|
||||
"* Number of divisors: [A000005](https://oeis.org/A000005)\n",
|
||||
"* Triangular numbers: [A000217](https://oeis.org/A000217)\n",
|
||||
"* Number of divisors of triangular numbers: [A063440](https://oeis.org/A063440)"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
|
|
@ -5,18 +5,7 @@
|
|||
"id": "43f43a42",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Longest Collatz Sequence\n",
|
||||
"> The following iterative sequence is defined for the set of positive integers:\n",
|
||||
"> * $n \\to n/2$ ($n$ is even)\n",
|
||||
"> * $n \\to 3n + 1$ ($n$ is odd)\n",
|
||||
"> \n",
|
||||
"> Using the rule above and starting with 13, we generate the following sequence: \n",
|
||||
"> $$13 \\to 40 \\to 20 \\to 10 \\to 5 \\to 16 \\to 8 \\to 4 \\to 2 \\to 1$$\n",
|
||||
"> It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1.\n",
|
||||
"> \n",
|
||||
"> Which starting number, under one million, produces the longest chain?\n",
|
||||
"> \n",
|
||||
"> **NOTE:** Once the chain starts the terms are allowed to go above one million.\n",
|
||||
"# [Longest Collatz Sequence](https://projecteuler.net/problem=14)\n",
|
||||
"\n",
|
||||
"The [Collatz conjecture](https://en.wikipedia.org/wiki/Collatz_conjecture) is a famous unsolved problem, and a classic example of a seemingly simple question that has proven very difficult, if not impossible, to answer.\n",
|
||||
"\n",
|
||||
|
@ -72,6 +61,15 @@
|
|||
"source": [
|
||||
"max(range(1, 1000000), key=collatz_length)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "bc0666ce",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Relevant sequences\n",
|
||||
"* Collatz chain lengths: [A008908](https://oeis.org/A008908)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
|
Loading…
Reference in New Issue