Compare commits

...

10 Commits

Author SHA1 Message Date
filifa ff67099715 add license 2025-07-25 23:18:36 -04:00
filifa 5b2c66538a add readme 2025-07-25 22:46:54 -04:00
filifa f0b7ed153c simplify condition 2025-07-25 21:46:59 -04:00
filifa be77271930 add copyright notice 2025-07-25 00:17:31 -04:00
filifa 5309593e70 refactor method 2025-07-23 23:18:49 -04:00
filifa d3701a5b61 add missing period 2025-07-23 22:34:03 -04:00
filifa 9671d506bd rephrase 2025-07-23 22:30:40 -04:00
filifa 849441f151 rename function 2025-07-23 21:57:24 -04:00
filifa 973da7e99d reorganize and elaborate 2025-07-23 21:52:55 -04:00
filifa 212eb04094 remove yield from in sieve 2025-07-22 23:22:57 -04:00
102 changed files with 1336 additions and 122 deletions

454
LICENSE Normal file
View File

@ -0,0 +1,454 @@
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0
International license and the BSD Zero Clause license.
BSD Zero Clause License
Copyright (C) 2025 by filifa
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
Attribution-ShareAlike 4.0 International
=======================================================================
Creative Commons Corporation ("Creative Commons") is not a law firm and
does not provide legal services or legal advice. Distribution of
Creative Commons public licenses does not create a lawyer-client or
other relationship. Creative Commons makes its licenses and related
information available on an "as-is" basis. Creative Commons gives no
warranties regarding its licenses, any material licensed under their
terms and conditions, or any related information. Creative Commons
disclaims all liability for damages resulting from their use to the
fullest extent possible.
Using Creative Commons Public Licenses
Creative Commons public licenses provide a standard set of terms and
conditions that creators and other rights holders may use to share
original works of authorship and other material subject to copyright
and certain other rights specified in the public license below. The
following considerations are for informational purposes only, are not
exhaustive, and do not form part of our licenses.
Considerations for licensors: Our public licenses are
intended for use by those authorized to give the public
permission to use material in ways otherwise restricted by
copyright and certain other rights. Our licenses are
irrevocable. Licensors should read and understand the terms
and conditions of the license they choose before applying it.
Licensors should also secure all rights necessary before
applying our licenses so that the public can reuse the
material as expected. Licensors should clearly mark any
material not subject to the license. This includes other CC-
licensed material, or material used under an exception or
limitation to copyright. More considerations for licensors:
wiki.creativecommons.org/Considerations_for_licensors
Considerations for the public: By using one of our public
licenses, a licensor grants the public permission to use the
licensed material under specified terms and conditions. If
the licensor's permission is not necessary for any reason--for
example, because of any applicable exception or limitation to
copyright--then that use is not regulated by the license. Our
licenses grant only permissions under copyright and certain
other rights that a licensor has authority to grant. Use of
the licensed material may still be restricted for other
reasons, including because others have copyright or other
rights in the material. A licensor may make special requests,
such as asking that all changes be marked or described.
Although not required by our licenses, you are encouraged to
respect those requests where reasonable. More considerations
for the public:
wiki.creativecommons.org/Considerations_for_licensees
=======================================================================
Creative Commons Attribution-ShareAlike 4.0 International Public
License
By exercising the Licensed Rights (defined below), You accept and agree
to be bound by the terms and conditions of this Creative Commons
Attribution-ShareAlike 4.0 International Public License ("Public
License"). To the extent this Public License may be interpreted as a
contract, You are granted the Licensed Rights in consideration of Your
acceptance of these terms and conditions, and the Licensor grants You
such rights in consideration of benefits the Licensor receives from
making the Licensed Material available under these terms and
conditions.
Section 1 -- Definitions.
a. Adapted Material means material subject to Copyright and Similar
Rights that is derived from or based upon the Licensed Material
and in which the Licensed Material is translated, altered,
arranged, transformed, or otherwise modified in a manner requiring
permission under the Copyright and Similar Rights held by the
Licensor. For purposes of this Public License, where the Licensed
Material is a musical work, performance, or sound recording,
Adapted Material is always produced where the Licensed Material is
synched in timed relation with a moving image.
b. Adapter's License means the license You apply to Your Copyright
and Similar Rights in Your contributions to Adapted Material in
accordance with the terms and conditions of this Public License.
c. BY-SA Compatible License means a license listed at
creativecommons.org/compatiblelicenses, approved by Creative
Commons as essentially the equivalent of this Public License.
d. Copyright and Similar Rights means copyright and/or similar rights
closely related to copyright including, without limitation,
performance, broadcast, sound recording, and Sui Generis Database
Rights, without regard to how the rights are labeled or
categorized. For purposes of this Public License, the rights
specified in Section 2(b)(1)-(2) are not Copyright and Similar
Rights.
e. Effective Technological Measures means those measures that, in the
absence of proper authority, may not be circumvented under laws
fulfilling obligations under Article 11 of the WIPO Copyright
Treaty adopted on December 20, 1996, and/or similar international
agreements.
f. Exceptions and Limitations means fair use, fair dealing, and/or
any other exception or limitation to Copyright and Similar Rights
that applies to Your use of the Licensed Material.
g. License Elements means the license attributes listed in the name
of a Creative Commons Public License. The License Elements of this
Public License are Attribution and ShareAlike.
h. Licensed Material means the artistic or literary work, database,
or other material to which the Licensor applied this Public
License.
i. Licensed Rights means the rights granted to You subject to the
terms and conditions of this Public License, which are limited to
all Copyright and Similar Rights that apply to Your use of the
Licensed Material and that the Licensor has authority to license.
j. Licensor means the individual(s) or entity(ies) granting rights
under this Public License.
k. Share means to provide material to the public by any means or
process that requires permission under the Licensed Rights, such
as reproduction, public display, public performance, distribution,
dissemination, communication, or importation, and to make material
available to the public including in ways that members of the
public may access the material from a place and at a time
individually chosen by them.
l. Sui Generis Database Rights means rights other than copyright
resulting from Directive 96/9/EC of the European Parliament and of
the Council of 11 March 1996 on the legal protection of databases,
as amended and/or succeeded, as well as other essentially
equivalent rights anywhere in the world.
m. You means the individual or entity exercising the Licensed Rights
under this Public License. Your has a corresponding meaning.
Section 2 -- Scope.
a. License grant.
1. Subject to the terms and conditions of this Public License,
the Licensor hereby grants You a worldwide, royalty-free,
non-sublicensable, non-exclusive, irrevocable license to
exercise the Licensed Rights in the Licensed Material to:
a. reproduce and Share the Licensed Material, in whole or
in part; and
b. produce, reproduce, and Share Adapted Material.
2. Exceptions and Limitations. For the avoidance of doubt, where
Exceptions and Limitations apply to Your use, this Public
License does not apply, and You do not need to comply with
its terms and conditions.
3. Term. The term of this Public License is specified in Section
6(a).
4. Media and formats; technical modifications allowed. The
Licensor authorizes You to exercise the Licensed Rights in
all media and formats whether now known or hereafter created,
and to make technical modifications necessary to do so. The
Licensor waives and/or agrees not to assert any right or
authority to forbid You from making technical modifications
necessary to exercise the Licensed Rights, including
technical modifications necessary to circumvent Effective
Technological Measures. For purposes of this Public License,
simply making modifications authorized by this Section 2(a)
(4) never produces Adapted Material.
5. Downstream recipients.
a. Offer from the Licensor -- Licensed Material. Every
recipient of the Licensed Material automatically
receives an offer from the Licensor to exercise the
Licensed Rights under the terms and conditions of this
Public License.
b. Additional offer from the Licensor -- Adapted Material.
Every recipient of Adapted Material from You
automatically receives an offer from the Licensor to
exercise the Licensed Rights in the Adapted Material
under the conditions of the Adapter's License You apply.
c. No downstream restrictions. You may not offer or impose
any additional or different terms or conditions on, or
apply any Effective Technological Measures to, the
Licensed Material if doing so restricts exercise of the
Licensed Rights by any recipient of the Licensed
Material.
6. No endorsement. Nothing in this Public License constitutes or
may be construed as permission to assert or imply that You
are, or that Your use of the Licensed Material is, connected
with, or sponsored, endorsed, or granted official status by,
the Licensor or others designated to receive attribution as
provided in Section 3(a)(1)(A)(i).
b. Other rights.
1. Moral rights, such as the right of integrity, are not
licensed under this Public License, nor are publicity,
privacy, and/or other similar personality rights; however, to
the extent possible, the Licensor waives and/or agrees not to
assert any such rights held by the Licensor to the limited
extent necessary to allow You to exercise the Licensed
Rights, but not otherwise.
2. Patent and trademark rights are not licensed under this
Public License.
3. To the extent possible, the Licensor waives any right to
collect royalties from You for the exercise of the Licensed
Rights, whether directly or through a collecting society
under any voluntary or waivable statutory or compulsory
licensing scheme. In all other cases the Licensor expressly
reserves any right to collect such royalties.
Section 3 -- License Conditions.
Your exercise of the Licensed Rights is expressly made subject to the
following conditions.
a. Attribution.
1. If You Share the Licensed Material (including in modified
form), You must:
a. retain the following if it is supplied by the Licensor
with the Licensed Material:
i. identification of the creator(s) of the Licensed
Material and any others designated to receive
attribution, in any reasonable manner requested by
the Licensor (including by pseudonym if
designated);
ii. a copyright notice;
iii. a notice that refers to this Public License;
iv. a notice that refers to the disclaimer of
warranties;
v. a URI or hyperlink to the Licensed Material to the
extent reasonably practicable;
b. indicate if You modified the Licensed Material and
retain an indication of any previous modifications; and
c. indicate the Licensed Material is licensed under this
Public License, and include the text of, or the URI or
hyperlink to, this Public License.
2. You may satisfy the conditions in Section 3(a)(1) in any
reasonable manner based on the medium, means, and context in
which You Share the Licensed Material. For example, it may be
reasonable to satisfy the conditions by providing a URI or
hyperlink to a resource that includes the required
information.
3. If requested by the Licensor, You must remove any of the
information required by Section 3(a)(1)(A) to the extent
reasonably practicable.
b. ShareAlike.
In addition to the conditions in Section 3(a), if You Share
Adapted Material You produce, the following conditions also apply.
1. The Adapter's License You apply must be a Creative Commons
license with the same License Elements, this version or
later, or a BY-SA Compatible License.
2. You must include the text of, or the URI or hyperlink to, the
Adapter's License You apply. You may satisfy this condition
in any reasonable manner based on the medium, means, and
context in which You Share Adapted Material.
3. You may not offer or impose any additional or different terms
or conditions on, or apply any Effective Technological
Measures to, Adapted Material that restrict exercise of the
rights granted under the Adapter's License You apply.
Section 4 -- Sui Generis Database Rights.
Where the Licensed Rights include Sui Generis Database Rights that
apply to Your use of the Licensed Material:
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
to extract, reuse, reproduce, and Share all or a substantial
portion of the contents of the database;
b. if You include all or a substantial portion of the database
contents in a database in which You have Sui Generis Database
Rights, then the database in which You have Sui Generis Database
Rights (but not its individual contents) is Adapted Material,
including for purposes of Section 3(b); and
c. You must comply with the conditions in Section 3(a) if You Share
all or a substantial portion of the contents of the database.
For the avoidance of doubt, this Section 4 supplements and does not
replace Your obligations under this Public License where the Licensed
Rights include other Copyright and Similar Rights.
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
c. The disclaimer of warranties and limitation of liability provided
above shall be interpreted in a manner that, to the extent
possible, most closely approximates an absolute disclaimer and
waiver of all liability.
Section 6 -- Term and Termination.
a. This Public License applies for the term of the Copyright and
Similar Rights licensed here. However, if You fail to comply with
this Public License, then Your rights under this Public License
terminate automatically.
b. Where Your right to use the Licensed Material has terminated under
Section 6(a), it reinstates:
1. automatically as of the date the violation is cured, provided
it is cured within 30 days of Your discovery of the
violation; or
2. upon express reinstatement by the Licensor.
For the avoidance of doubt, this Section 6(b) does not affect any
right the Licensor may have to seek remedies for Your violations
of this Public License.
c. For the avoidance of doubt, the Licensor may also offer the
Licensed Material under separate terms or conditions or stop
distributing the Licensed Material at any time; however, doing so
will not terminate this Public License.
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
License.
Section 7 -- Other Terms and Conditions.
a. The Licensor shall not be bound by any additional or different
terms or conditions communicated by You unless expressly agreed.
b. Any arrangements, understandings, or agreements regarding the
Licensed Material not stated herein are separate from and
independent of the terms and conditions of this Public License.
Section 8 -- Interpretation.
a. For the avoidance of doubt, this Public License does not, and
shall not be interpreted to, reduce, limit, restrict, or impose
conditions on any use of the Licensed Material that could lawfully
be made without permission under this Public License.
b. To the extent possible, if any provision of this Public License is
deemed unenforceable, it shall be automatically reformed to the
minimum extent necessary to make it enforceable. If the provision
cannot be reformed, it shall be severed from this Public License
without affecting the enforceability of the remaining terms and
conditions.
c. No term or condition of this Public License will be waived and no
failure to comply consented to unless expressly agreed to by the
Licensor.
d. Nothing in this Public License constitutes or may be interpreted
as a limitation upon, or waiver of, any privileges and immunities
that apply to the Licensor or You, including from the legal
processes of any jurisdiction or authority.
=======================================================================
Creative Commons is not a party to its public
licenses. Notwithstanding, Creative Commons may elect to apply one of
its public licenses to material it publishes and in those instances
will be considered the “Licensor.” The text of the Creative Commons
public licenses is dedicated to the public domain under the CC0 Public
Domain Dedication. Except for the limited purpose of indicating that
material is shared under a Creative Commons public license or as
otherwise permitted by the Creative Commons policies published at
creativecommons.org/policies, Creative Commons does not authorize the
use of the trademark "Creative Commons" or any other trademark or logo
of Creative Commons without its prior written consent including,
without limitation, in connection with any unauthorized modifications
to any of its public licenses or any other arrangements,
understandings, or agreements concerning use of licensed material. For
the avoidance of doubt, this paragraph does not form part of the
public licenses.
Creative Commons may be contacted at creativecommons.org.

39
README.md Normal file
View File

@ -0,0 +1,39 @@
# eulerbooks
This is a collection of Jupyter notebooks containing solutions and discussions
for the first 100 [Project Euler problems](https://projecteuler.net) using
[SageMath](https://www.sagemath.org).
My main goal with these notebooks is not simply to provide working code for
solving the problems. Frequently, solutions to these problems are short, but
they're not always easy to follow without understanding some important
mathematical principles. Therefore, my aim is to provide insight into the
underlying algorithms and mathematical concepts that make an efficient solution
possible. I personally find that these topics are frequently even more
interesting than the problems themselves, which I see as mainly existing to
provide situations to apply the concepts after learning about them. In short,
it's more about the journey, not the destination, so these notebooks mainly
exist to discuss the former.
## Approach
Frequently, either Python or SageMath provide functions and libraries that make
it trivially easy to write a solution. I don't have a problem with presenting
solutions that use these, since for practical purposes, it's better to use
what's already available than to reinvent the wheel. It also tends to lead to
code that is easy to read and understand, which is the best kind of code.
However, when a function already exists that does the heavy lifting, I also
tend to provide my own basic implementation and an explanation of why it works.
This is especially true if a solution or algorithm is based off of an important
mathematical concept that is not especially intuitive.
When not especially tedious, I like writing up solutions that do not require
programming at all, since these approaches often require interesting
mathematical techniques.
Another thing to note is that I don't prioritize a solution's performance above
all. When a solution is fast enough (using Project Euler's own "one-minute
rule" as a rule of thumb), I instead usually focus on making the code easy to
read. You can basically always optimize, but there are frequently diminishing
returns, and it tends to negatively impact readability. Once a solution is fast
enough to solve the problem at hand, I only consider optimizing further if the
concepts are reusable.

View File

@ -34,7 +34,10 @@
"\n",
"## Relevant sequences\n",
"* Triangular numbers: [A000217](https://oeis.org/A000217)\n",
"* Multiples of 3 and/or 5: [A281746](https://oeis.org/A281746)"
"* Multiples of 3 and/or 5: [A281746](https://oeis.org/A281746)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -63,7 +63,11 @@
"source": [
"## Relevant sequences\n",
"* Fibonacci numbers: [A000045](https://oeis.org/A000045)\n",
"* Partial sums of even Fibonacci numbers: [A099919](https://oeis.org/A099919)"
"* Partial sums of even Fibonacci numbers: [A099919](https://oeis.org/A099919)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -101,7 +101,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Greatest prime factors: [A006530](https://oeis.org/A006530)"
"* Greatest prime factors: [A006530](https://oeis.org/A006530)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -34,6 +34,16 @@
"three_digit_pairs = combinations(range(100, 1000), 2)\n",
"max(x*y for (x,y) in three_digit_pairs if is_palindrome(x*y))"
]
},
{
"cell_type": "markdown",
"id": "ac68b4da",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -49,7 +49,11 @@
"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).\n",
"\n",
"## Relevant sequences\n",
"* Least common multiple of $1,2,\\ldots,n$: [A003418](https://oeis.org/A003418)"
"* Least common multiple of $1,2,\\ldots,n$: [A003418](https://oeis.org/A003418)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -21,7 +21,11 @@
"\n",
"## Relevant sequences\n",
"* Triangular numbers: [A000217](https://oeis.org/A000217)\n",
"* Square pyramidal numbers: [A000330](https://oeis.org/A000330)"
"* Square pyramidal numbers: [A000330](https://oeis.org/A000330)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -160,7 +160,11 @@
"source": [
"## Relevant sequences\n",
"* Prime numbers: [A000040](https://oeis.org/A000040)\n",
"* Carmichael numbers: [A002997](https://oeis.org/A002997)"
"* Carmichael numbers: [A002997](https://oeis.org/A002997)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -55,7 +55,11 @@
"id": "4148d160",
"metadata": {},
"source": [
"Their product is 23514624000."
"Their product is 23514624000.\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -30,7 +30,7 @@
"def primitive_pythagorean_triplets():\n",
" for m in count(2):\n",
" for n in range(1, m):\n",
" if not ((m % 2) != (n % 2)) or gcd(m, n) != 1:\n",
" if ((m % 2) == (n % 2)) or gcd(m, n) != 1:\n",
" continue\n",
"\n",
" a = m ** 2 - n ** 2\n",
@ -84,7 +84,11 @@
"id": "8809ed3b",
"metadata": {},
"source": [
"So our product is $abc=31875000$."
"So our product is $abc=31875000$.\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -66,7 +66,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Partial sums of primes: [A007504](https://oeis.org/A007504)"
"* Partial sums of primes: [A007504](https://oeis.org/A007504)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -77,6 +77,16 @@
"\n",
"print(maximum)"
]
},
{
"cell_type": "markdown",
"id": "8626099f",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -58,7 +58,11 @@
"## 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)"
"* Number of divisors of triangular numbers: [A063440](https://oeis.org/A063440)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -147,6 +147,16 @@
"source": [
"int(str(sum(nums))[:10])"
]
},
{
"cell_type": "markdown",
"id": "dfce30f6",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -68,7 +68,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Collatz chain lengths: [A008908](https://oeis.org/A008908)"
"* Collatz chain lengths: [A008908](https://oeis.org/A008908)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -88,7 +88,11 @@
"source": [
"## Relevant sequences\n",
"* Central binomial coefficients: [A000984](https://oeis.org/A000984)\n",
"* General formula: [A046899](https://oeis.org/A046899)"
"* General formula: [A046899](https://oeis.org/A046899)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -40,7 +40,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Sums of digits of $2^n$: [A001370](https://oeis.org/A001370)"
"* Sums of digits of $2^n$: [A001370](https://oeis.org/A001370)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -119,7 +119,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Number of letters in British numeral: [A362123](https://oeis.org/A362123)"
"* Number of letters in British numeral: [A362123](https://oeis.org/A362123)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -153,6 +153,16 @@
"\n",
"max_path_sum(triangle)"
]
},
{
"cell_type": "markdown",
"id": "1d84d533",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -114,7 +114,11 @@
"id": "83b6e18e",
"metadata": {},
"source": [
"One last note, just for fun: did you know you can learn how to calculate what day of the week any date falls on [in your head](https://en.wikipedia.org/wiki/Doomsday_rule)?"
"One last note, just for fun: did you know you can learn how to calculate what day of the week any date falls on [in your head](https://en.wikipedia.org/wiki/Doomsday_rule)?\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -37,7 +37,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Sum of digits of $n!$: [A004152](https://oeis.org/A004152)"
"* Sum of digits of $n!$: [A004152](https://oeis.org/A004152)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -9,30 +9,57 @@
"\n",
"The sum of the proper divisors of a number is called the [aliquot sum](https://en.wikipedia.org/wiki/Aliquot_sum).\n",
"\n",
"SageMath [provides the `sigma` function](https://doc.sagemath.org/html/en/reference/rings_standard/sage/arith/misc.html#sage.arith.misc.Sigma), which can compute the sum of the divisors of $n$. The aliquot sum is then just `sigma(n) - n`.\n",
"\n",
"If a number is equal to its own aliquot sum, it's called a [perfect number](https://en.wikipedia.org/wiki/Perfect_number), and we exclude those numbers from our total."
"SageMath [provides the `sigma` function](https://doc.sagemath.org/html/en/reference/rings_standard/sage/arith/misc.html#sage.arith.misc.Sigma), which can compute the sum of the divisors of $n$. The aliquot sum is then just `sigma(n) - n`."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "49bbab13",
"metadata": {},
"outputs": [],
"source": [
"def aliquot_sum(n): return sigma(n) - n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "c57c9f76",
"metadata": {},
"outputs": [],
"source": [
"limit = 10000"
]
},
{
"cell_type": "markdown",
"id": "a2fe4975",
"metadata": {},
"source": [
"If a number is equal to its own aliquot sum, it's called a [perfect number](https://en.wikipedia.org/wiki/Perfect_number), and we exclude those numbers from our total."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "144e1f54",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"31626\n"
"data": {
"text/plain": [
"31626"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"aliquot_sum = lambda n: sigma(n) - n\n",
"\n",
"amicables = set()\n",
"for a in range(2, 10000):\n",
"for a in range(2, limit):\n",
" if a in amicables:\n",
" continue\n",
" \n",
@ -43,7 +70,36 @@
" if a == aliquot_sum(b):\n",
" amicables.update({a, b})\n",
" \n",
"print(sum(amicables))"
"sum(amicables)"
]
},
{
"cell_type": "markdown",
"id": "5b540764",
"metadata": {},
"source": [
"Funny enough, there's only five pairs of amicable numbers below 10,000. If you looked up [amicable numbers](https://en.wikipedia.org/wiki/Amicable_numbers), you may have stumbled on all the numbers you need to answer the problem!"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "f6014a35",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{220, 284, 1184, 1210, 2620, 2924, 5020, 5564, 6232, 6368}"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"amicables"
]
},
{
@ -51,8 +107,6 @@
"id": "ca7d5f36",
"metadata": {},
"source": [
"Funny enough, there's only five pairs of amicable numbers below 10,000. If you looked up [amicable numbers](https://en.wikipedia.org/wiki/Amicable_numbers), you may have stumbled on all the numbers you need to answer the problem!\n",
"\n",
"## Sum of divisors\n",
"Of course, you could implement your own [divisor sum function](https://en.wikipedia.org/wiki/Divisor_function). In [problem 12](https://projecteuler.net/problem=12), we implemented a divisor *counting* function, which is related.\n",
"\n",
@ -67,31 +121,110 @@
"\n",
"Therefore, if you have the number's factorization (see [problem 3](https://projecteuler.net/problem=3)), you can use it to compute the sum of its divisors.\n",
"\n",
"## Sieving the sums of divisors\n",
"Since we need all the sums of divisors up to 10000, instead of factoring each number individually, we could sieve the values of $\\sigma$."
"## Avoiding factoring\n",
"Since we need all the sums of divisors up to 10000, instead of factoring each number individually, we can compute each value of $\\sigma$ in a loop, once again taking advantage of $\\sigma$ being multiplicative. (In some ways, this method is similar to the sieve of Eratosthenes - see [problem 10](https://projecteuler.net/problem=10).)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 5,
"id": "4cbc68db",
"metadata": {},
"outputs": [],
"source": [
"def sum_of_divisors_sieve(limit):\n",
" dsum = [1 for _ in range(0, limit)]\n",
"def update_multiples(dsum, p, limit):\n",
" q = p\n",
" while True:\n",
" # sigma(a*b) = sigma(a) * sigma(b) if gcd(a, b) = 1\n",
" for k in range(2 * q, limit, q):\n",
" if k % (p*q) != 0:\n",
" dsum[k] *= dsum[q]\n",
"\n",
" if p * q >= limit:\n",
" break\n",
"\n",
" # sigma(p^k) = p^k + sigma(p^(k-1))\n",
" dsum[p*q] = p * q + dsum[q]\n",
" q *= p\n",
" \n",
"\n",
"def sum_of_divisors_range(limit): \n",
" dsum = [1 for n in range(0, limit)]\n",
" dsum[0] = 0\n",
" \n",
" for n in range(0, limit):\n",
" if n == 0 or n == 1:\n",
" if n == 0 or n == 1 or dsum[n] != 1:\n",
" # n is 0, 1, or composite\n",
" yield dsum[n]\n",
" continue\n",
"\n",
" for k in range(n, limit, n):\n",
" dsum[k] += n\n",
" \n",
" # n is prime\n",
" dsum[n] = n + 1\n",
" update_multiples(dsum, n, limit)\n",
" yield dsum[n]"
]
},
{
"cell_type": "markdown",
"id": "f4dc20fe",
"metadata": {},
"source": [
"With this method, we can redefine our aliquot sum function:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "6b5cb5f8",
"metadata": {},
"outputs": [],
"source": [
"divisor_sums = list(sum_of_divisors_range(limit))\n",
"def aliquot_sum(n): return divisor_sums[n] - n"
]
},
{
"cell_type": "markdown",
"id": "bf501433",
"metadata": {},
"source": [
"Then we compute the amicable numbers the same as before."
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "2f70d28c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"31626"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"amicables = set()\n",
"for a in range(2, limit):\n",
" if a in amicables:\n",
" continue\n",
" \n",
" b = aliquot_sum(a)\n",
" if a == b:\n",
" continue\n",
" \n",
" # if b is greater than limit, it will cause an IndexError\n",
" if b < limit and a == aliquot_sum(b):\n",
" amicables.update({a, b})\n",
" \n",
"sum(amicables)"
]
},
{
"cell_type": "markdown",
"id": "a847f754",
@ -99,7 +232,11 @@
"source": [
"## Relevant sequences\n",
"* Sums of divisors: [A000203](https://oeis.org/A000203)\n",
"* Amicable numbers: [A063990](https://oeis.org/A063990)"
"* Amicable numbers: [A063990](https://oeis.org/A063990)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -60,6 +60,16 @@
"\n",
"sum(name_score(i, name) for (i, name) in enumerate(names, start=1))"
]
},
{
"cell_type": "markdown",
"id": "7c61f808",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -64,7 +64,11 @@
"source": [
"## Relevant sequences\n",
"* Sums of divisors: [A000203](https://oeis.org/A000203)\n",
"* Numbers that are not the sum of two abundant numbers: [A048242](https://oeis.org/A048242)"
"* Numbers that are not the sum of two abundant numbers: [A048242](https://oeis.org/A048242)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -98,6 +98,16 @@
" lst[i+1:] = lst[i+1:][::-1]\n",
" break"
]
},
{
"cell_type": "markdown",
"id": "cde4b894",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -29,7 +29,11 @@
"Therefore, we want $n=4782$.\n",
"\n",
"## Relevant sequences\n",
"* Fibonacci numbers: [A000045](https://oeis.org/A000045)"
"* Fibonacci numbers: [A000045](https://oeis.org/A000045)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -101,7 +101,11 @@
"As a concrete example of the above, consider $d = 2^4 \\times 5 \\times 63 = 5040$. The decimal representation of $u = \\frac{1}{d}$ is $0.0001(984126)$, where 984126 is the repetend. Therefore $q=4$ and $r=6$. Sure enough, $10^q 10^r u - 10^q u = 1984125$ is an integer; therefore, $10^{10} \\equiv 10^4 \\pmod{5040}$, and $10^6 \\equiv 1 \\pmod{63}$.\n",
"\n",
"## Relevant sequences\n",
"* Periods of reciprocals: [A007732](https://oeis.org/A007732)"
"* Periods of reciprocals: [A007732](https://oeis.org/A007732)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

File diff suppressed because one or more lines are too long

View File

@ -22,7 +22,11 @@
"Side note: this practice of writing the natural numbers in a spiral, combined with marking the prime numbers, has been coined the [Ulam spiral](https://en.wikipedia.org/wiki/Ulam_spiral). Somewhat interestingly, lots of primes appear in vertical, horizontal, and diagonal lines when laid out this way.\n",
"\n",
"## Relevant sequences\n",
"* Numbers on diagonals: [A200975](https://oeis.org/A200975)"
"* Numbers on diagonals: [A200975](https://oeis.org/A200975)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -30,6 +30,16 @@
"source": [
"len({a ** b for a in range(2, 101) for b in range(2, 101)})"
]
},
{
"cell_type": "markdown",
"id": "d7afa770",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -74,7 +74,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Perfect digital invariants: [A252648](https://oeis.org/A252648)"
"* Perfect digital invariants: [A252648](https://oeis.org/A252648)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -235,7 +235,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Number of ways to make change with Euro currency (same values as this problem until $n=500$): [A057537](https://oeis.org/A057537)"
"* Number of ways to make change with Euro currency (same values as this problem until $n=500$): [A057537](https://oeis.org/A057537)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -93,6 +93,16 @@
"source": [
"sum(set(products.values()))"
]
},
{
"cell_type": "markdown",
"id": "04862a57",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -102,6 +102,16 @@
"source": [
"prod(QQ(n/d) for (n, d) in fractions).denominator()"
]
},
{
"cell_type": "markdown",
"id": "1514f872",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -98,7 +98,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Factorions: [A014080](https://oeis.org/A014080)"
"* Factorions: [A014080](https://oeis.org/A014080)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -56,7 +56,11 @@
"Another note - there aren't that many known circular primes, and all of the known ones greater than one million are [repunits](https://en.wikipedia.org/wiki/Repunit).\n",
"\n",
"## Relevant sequences\n",
"* Circular primes: [A068652](https://oeis.org/A068652)"
"* Circular primes: [A068652](https://oeis.org/A068652)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -80,7 +80,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Numbers that are base-2 and base-10 palindromes: [A007632](https://oeis.org/A007632)"
"* Numbers that are base-2 and base-10 palindromes: [A007632](https://oeis.org/A007632)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -222,7 +222,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Two-sided primes: [A020994](https://oeis.org/A020994)"
"* Two-sided primes: [A020994](https://oeis.org/A020994)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -93,6 +93,16 @@
"source": [
"max(pandigitals.values())"
]
},
{
"cell_type": "markdown",
"id": "094c440b",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -140,7 +140,11 @@
"metadata": {},
"source": [
"## Related sequences\n",
"* Number of integer right triangles with perimeter $n$: [A024155](https://oeis.org/A024155)"
"* Number of integer right triangles with perimeter $n$: [A024155](https://oeis.org/A024155)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -42,7 +42,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Digits of Champernowne's constant: [A033307](https://oeis.org/A033307)"
"* Digits of Champernowne's constant: [A033307](https://oeis.org/A033307)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -74,7 +74,11 @@
"source": [
"## Relevant sequences\n",
"* Pandigital numbers: [A352991](https://oeis.org/A352991)\n",
"* Pandigital primes: [A216444](https://oeis.org/A216444)"
"* Pandigital primes: [A216444](https://oeis.org/A216444)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -78,6 +78,16 @@
"triangle_words = {w for w in words if is_triangle_word(w)}\n",
"len(triangle_words)"
]
},
{
"cell_type": "markdown",
"id": "02bf08bf",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -99,7 +99,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Pandigital numbers: [A050278](https://oeis.org/A050278)"
"* Pandigital numbers: [A050278](https://oeis.org/A050278)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -243,7 +243,11 @@
"\n",
"## Relevant sequences\n",
"* Pentagonal numbers: [A000326](https://oeis.org/A000326)\n",
"* Pentagonal numbers which are the sum of two other positive pentagonal numbers: [A136117](https://oeis.org/A136117)"
"* Pentagonal numbers which are the sum of two other positive pentagonal numbers: [A136117](https://oeis.org/A136117)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -46,8 +46,8 @@
{
"data": {
"text/plain": [
"(1/12*(2107560*sqrt(3) + 3650401)^t*(3*sqrt(3) + 5) - 1/12*(-2107560*sqrt(3) + 3650401)^t*(3*sqrt(3) - 5) + 1/6,\n",
" 1/24*sqrt(3)*((2107560*sqrt(3) + 3650401)^t*(3*sqrt(3) + 5) + (-2107560*sqrt(3) + 3650401)^t*(3*sqrt(3) - 5)) + 1/4)"
"(-1/12*(2107560*sqrt(3) + 3650401)^t*(153*sqrt(3) + 265) + 1/12*(-2107560*sqrt(3) + 3650401)^t*(153*sqrt(3) - 265) + 1/6,\n",
" -1/24*sqrt(3)*((2107560*sqrt(3) + 3650401)^t*(153*sqrt(3) + 265) + (-2107560*sqrt(3) + 3650401)^t*(153*sqrt(3) - 265)) + 1/4)"
]
},
"execution_count": 2,
@ -337,7 +337,11 @@
"* [Pell's Equation, II](https://kconrad.math.uconn.edu/blurbs/ugradnumthy/pelleqn2.pdf)\n",
"\n",
"## Relevant sequences\n",
"* Hexagonal pentagonal numbers: [A046180](https://oeis.org/A046180)"
"* Hexagonal pentagonal numbers: [A046180](https://oeis.org/A046180)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -65,7 +65,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Stern numbers (includes all odd numbers, not just composites): [A060003](https://oeis.org/A060003)"
"* Stern numbers (includes all odd numbers, not just composites): [A060003](https://oeis.org/A060003)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -49,7 +49,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Number of distinct prime factors: [A001221](https://oeis.org/A001221)"
"* Number of distinct prime factors: [A001221](https://oeis.org/A001221)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -5,7 +5,7 @@
"id": "e829e539",
"metadata": {},
"source": [
"# [Self Powers](https://projecteuler.net/problem=48)\n",
"## [Self Powers](https://projecteuler.net/problem=48)\n",
"\n",
"Easy with [modular exponentiation](https://en.wikipedia.org/wiki/Modular_exponentiation), which is built into Python."
]
@ -47,7 +47,11 @@
"\n",
"## Relevant sequences\n",
"* $n^n$: [A000312](https://oeis.org/A000312)\n",
"* Partial sums of $n^n$: [A001923](https://oeis.org/A001923)"
"* Partial sums of $n^n$: [A001923](https://oeis.org/A001923)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -111,6 +111,16 @@
" \n",
"p, q, r"
]
},
{
"cell_type": "markdown",
"id": "929e777d",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -130,7 +130,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Primes expressible as the sum of (at least two) consecutive primes in at least 1 way: [A067377](https://oeis.org/A067377)"
"* Primes expressible as the sum of (at least two) consecutive primes in at least 1 way: [A067377](https://oeis.org/A067377)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -159,6 +159,16 @@
"source": [
"min(f)"
]
},
{
"cell_type": "markdown",
"id": "8cc3e0f4",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -40,6 +40,16 @@
" \n",
"n"
]
},
{
"cell_type": "markdown",
"id": "898f292d",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -50,7 +50,11 @@
"$\\log{n!}$ can be computed in a number of ways. You can use the [log-gamma function](https://en.wikipedia.org/wiki/Gamma_function), or you can implement a function yourself, either by applying logarithmic identities again:\n",
"$$\\log{n!} = \\log{1} + \\log{2} + \\log{3} \\cdots + \\log{n}$$\n",
"or by using [Stirling's approximation](https://en.wikipedia.org/wiki/Stirling%27s_approximation):\n",
"$$\\log{n!} \\approx \\left(n + \\frac{1}{2}\\right)\\log{n} - n + \\frac{1}{2}\\log{2\\pi}$$"
"$$\\log{n!} \\approx \\left(n + \\frac{1}{2}\\right)\\log{n} - n + \\frac{1}{2}\\log{2\\pi}$$\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -238,6 +238,16 @@
"wins = [i for (i, (x, y)) in enumerate(hands) if x > y]\n",
"len(wins)"
]
},
{
"cell_type": "markdown",
"id": "dc2baa5b",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -77,7 +77,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Suspected Lychrel numbers: [A023108](https://oeis.org/A023108)"
"* Suspected Lychrel numbers: [A023108](https://oeis.org/A023108)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -46,6 +46,16 @@
"source": [
"max(digit_sum(a^b) for a in range(1, 100) for b in range(1, 100))"
]
},
{
"cell_type": "markdown",
"id": "d6f7d0af",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -147,7 +147,11 @@
"source": [
"## Relevant sequences\n",
"* Numerators of convergents of $\\sqrt{2}$: [A001333](https://oeis.org/A001333)\n",
"* Pell numbers (denominators of convergents of $\\sqrt{2}$): [A000129](https://oeis.org/A000129)"
"* Pell numbers (denominators of convergents of $\\sqrt{2}$): [A000129](https://oeis.org/A000129)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -63,7 +63,11 @@
"source": [
"## Relevant sequences\n",
"* Numbers on diagonals: [A200975](https://oeis.org/A200975)\n",
"* Primes at right-angle turns on the Ulam spiral: [A172979](https://oeis.org/A172979)"
"* Primes at right-angle turns on the Ulam spiral: [A172979](https://oeis.org/A172979)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -183,6 +183,16 @@
"source": [
"sum(plaintext)"
]
},
{
"cell_type": "markdown",
"id": "e8832df2",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -215,6 +215,16 @@
"min_clique = min(cliques, key=sum)\n",
"min_clique"
]
},
{
"cell_type": "markdown",
"id": "07fc52d8",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -206,7 +206,11 @@
"* Pentagonal numbers: [A000326](https://oeis.org/A000326)\n",
"* Hexagonal numbers: [A000384](https://oeis.org/A000384)\n",
"* Heptagonal numbers: [A000566](https://oeis.org/A000566)\n",
"* Octagonal numbers: [A000567](https://oeis.org/A000567)"
"* Octagonal numbers: [A000567](https://oeis.org/A000567)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -89,6 +89,16 @@
"source": [
"min(s)"
]
},
{
"cell_type": "markdown",
"id": "1701dfc7",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -21,7 +21,11 @@
"$$9 + 6 + 5 + 4 + 3 + 3 + 2 + 2 + 2 + 2 + 1 \\times 11 = 49$$\n",
"\n",
"## Relevant sequences\n",
"* Numbers with $k$ digits that are also $k$th powers: [A132722](https://oeis.org/A132722)"
"* Numbers with $k$ digits that are also $k$th powers: [A132722](https://oeis.org/A132722)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -115,7 +115,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Periods of continued fractions of $\\sqrt{n}$: [A003285](https://oeis.org/A003285)"
"* Periods of continued fractions of $\\sqrt{n}$: [A003285](https://oeis.org/A003285)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -116,7 +116,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Numerators of convergents of $e$: [A007676](https://oeis.org/A007676)"
"* Numerators of convergents of $e$: [A007676](https://oeis.org/A007676)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -19,10 +19,10 @@
{
"data": {
"text/plain": [
"[(-sqrt(2)*(2*sqrt(2) + 3)^t + sqrt(2)*(-2*sqrt(2) + 3)^t - 3/2*(2*sqrt(2) + 3)^t - 3/2*(-2*sqrt(2) + 3)^t,\n",
" 3/4*sqrt(2)*(2*sqrt(2) + 3)^t - 3/4*sqrt(2)*(-2*sqrt(2) + 3)^t + (2*sqrt(2) + 3)^t + (-2*sqrt(2) + 3)^t),\n",
" (sqrt(2)*(2*sqrt(2) + 3)^t - sqrt(2)*(-2*sqrt(2) + 3)^t + 3/2*(2*sqrt(2) + 3)^t + 3/2*(-2*sqrt(2) + 3)^t,\n",
" -3/4*sqrt(2)*(2*sqrt(2) + 3)^t + 3/4*sqrt(2)*(-2*sqrt(2) + 3)^t - (2*sqrt(2) + 3)^t - (-2*sqrt(2) + 3)^t)]"
"[(sqrt(2)*(2*sqrt(2) + 3)^t - sqrt(2)*(-2*sqrt(2) + 3)^t + 3/2*(2*sqrt(2) + 3)^t + 3/2*(-2*sqrt(2) + 3)^t,\n",
" -3/4*sqrt(2)*(2*sqrt(2) + 3)^t + 3/4*sqrt(2)*(-2*sqrt(2) + 3)^t - (2*sqrt(2) + 3)^t - (-2*sqrt(2) + 3)^t),\n",
" (-sqrt(2)*(2*sqrt(2) + 3)^t + sqrt(2)*(-2*sqrt(2) + 3)^t - 3/2*(2*sqrt(2) + 3)^t - 3/2*(-2*sqrt(2) + 3)^t,\n",
" 3/4*sqrt(2)*(2*sqrt(2) + 3)^t - 3/4*sqrt(2)*(-2*sqrt(2) + 3)^t + (2*sqrt(2) + 3)^t + (-2*sqrt(2) + 3)^t)]"
]
},
"execution_count": 1,
@ -184,7 +184,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Minimal values of $x$ for solutions to the Pell equation: [A002350](https://oeis.org/A002350)"
"* Minimal values of $x$ for solutions to the Pell equation: [A002350](https://oeis.org/A002350)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -58,6 +58,16 @@
"\n",
"max_path_sum(triangle)"
]
},
{
"cell_type": "markdown",
"id": "f06b0164",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -157,6 +157,16 @@
"source": [
"max((s for s in sols if len(s) == 16), key=int)"
]
},
{
"cell_type": "markdown",
"id": "e5000191",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -51,7 +51,11 @@
"source": [
"## Relevant sequences\n",
"* Totient: [A000010](https://oeis.org/A000010)\n",
"* Primorial numbers: [A002110](https://oeis.org/A002110)"
"* Primorial numbers: [A002110](https://oeis.org/A002110)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -42,20 +42,18 @@
"metadata": {},
"outputs": [],
"source": [
"def totient_sieve(limit):\n",
"def totient_range(limit):\n",
" totients = [n - 1 for n in range(0, limit)]\n",
" totients[0] = 0\n",
" totients[1] = 1\n",
" \n",
" for n in range(0, limit // 2 + 1):\n",
" for n in range(0, limit):\n",
" yield totients[n]\n",
" if n == 0 or n == 1 or totients[n] != n - 1:\n",
" continue\n",
"\n",
" for k in range(2 * n, limit, n):\n",
" totients[k] -= totients[k] // n\n",
" \n",
" yield from totients[limit // 2 + 1:]"
" totients[k] -= totients[k] // n"
]
},
{
@ -78,7 +76,7 @@
"answer = None\n",
"ratio = float('inf')\n",
"\n",
"for (n, totient) in enumerate(totient_sieve(limit)):\n",
"for (n, totient) in enumerate(totient_range(limit)):\n",
" if n == 0 or n == 1 or totient == n - 1:\n",
" continue\n",
" \n",
@ -118,7 +116,11 @@
"\n",
"## Relevant sequences\n",
"* All numbers $n$ such that $\\phi(n)$ is a digit permutation: [A115921](https://oeis.org/A115921)\n",
"* Subsequence of A115921 such that $n/\\phi(n)$ is a record low: [A102018](https://oeis.org/A102018)"
"* Subsequence of A115921 such that $n/\\phi(n)$ is a record low: [A102018](https://oeis.org/A102018)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -22,7 +22,11 @@
"Therefore, we just need to find the largest $n$ such that $5 + 7n \\leq 1000000$, which is $n=142856$. This gives us a numerator of 428570.\n",
"\n",
"## Relevant sequences\n",
"* Numerators of Farey sequences: [A007305](https://oeis.org/A007305)"
"* Numerators of Farey sequences: [A007305](https://oeis.org/A007305)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -50,7 +50,7 @@
"id": "8e268820",
"metadata": {},
"source": [
"If you try to implement the totient function yourself, you might find it difficult to make this approach fast enough. An alternative is to sieve the values of totient - see [problem 70](https://projecteuler.net/problem=70). However, there's a few more *very* interesting methods to compute totient sums.\n",
"If you try to implement the totient function yourself, you might find it difficult to make this approach fast enough. An alternative is to \"sieve\" the values of totient - see [problem 70](https://projecteuler.net/problem=70). However, there's a few more *very* interesting methods to compute totient sums.\n",
"\n",
"## Recursive totient sum\n",
"\n",
@ -159,7 +159,7 @@
"\n",
"$$M(n) = 1 + \\lfloor b\\rfloor M(\\lfloor a\\rfloor) - \\sum_{x=1}^a \\mu(x)\\left\\lfloor \\frac{n}{x}\\right\\rfloor - \\sum_{y=2}^b M\\left(\\left\\lfloor \\frac{n}{y}\\right\\rfloor\\right)$$\n",
"\n",
"Now we have a recursive implementation of $M(n)$. All that's left is to calculate the values of $\\mu(n)$ that we need. We can do this with a sieve, since $\\mu$ is a [multiplicative function](https://en.wikipedia.org/wiki/Multiplicative_function)."
"Now we have a recursive implementation of $M(n)$. All that's left is to calculate the values of $\\mu(n)$ that we need. By taking advantage of $\\mu$ being [multiplicative](https://en.wikipedia.org/wiki/Multiplicative_function), we can compute values using a similar strategy to the sieve of Eratosthenes - see [problem 10](https://projecteuler.net/problem=10)."
]
},
{
@ -169,9 +169,7 @@
"metadata": {},
"outputs": [],
"source": [
"from math import isqrt\n",
"\n",
"def mobius_sieve(limit):\n",
"def mobius_range(limit):\n",
" ms = [n for n in range(0, limit)]\n",
"\n",
" for n in range(0, limit):\n",
@ -193,7 +191,7 @@
"id": "f12a8b30",
"metadata": {},
"source": [
"We'll use $a = \\sqrt{1000000} = 1000$ as our upper bound on the sieve."
"We'll use $a = \\sqrt{1000000} = 1000$ as our upper bound."
]
},
{
@ -203,7 +201,8 @@
"metadata": {},
"outputs": [],
"source": [
"mu = list(mobius_sieve(isqrt(1000000) + 1))"
"from math import isqrt\n",
"mu = list(mobius_range(isqrt(1000000) + 1))"
]
},
{
@ -300,7 +299,11 @@
"source": [
"## Relevant sequences\n",
"* Cardinalities of Farey sequences: [A005728](https://oeis.org/A005728)\n",
"* Partial sums of totient function: [A002088](https://oeis.org/A002088)"
"* Partial sums of totient function: [A002088](https://oeis.org/A002088)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -70,6 +70,16 @@
" \n",
"total"
]
},
{
"cell_type": "markdown",
"id": "192090b1",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -203,7 +203,11 @@
"source": [
"## Relevant sequences\n",
"* Numbers that eventually cycle when summing digit factorials: [A188284](https://oeis.org/A188284)\n",
"* Digit factorial chain lengths: [A303935](https://oeis.org/A303935)"
"* Digit factorial chain lengths: [A303935](https://oeis.org/A303935)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -102,7 +102,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Perimeters with one Pythagorean triple: [A098714](https://oeis.org/A098714)"
"* Perimeters with one Pythagorean triple: [A098714](https://oeis.org/A098714)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -70,7 +70,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Partition numbers: [A000041](https://oeis.org/A000041)"
"* Partition numbers: [A000041](https://oeis.org/A000041)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -86,7 +86,11 @@
"We can see that $x^{71}$ is our first term with a coeffcient over 5000, so our answer is 71.\n",
"\n",
"## Relevant sequences\n",
"* Number of partitions of $n$ into prime parts: [A000607](https://oeis.org/A000607)"
"* Number of partitions of $n$ into prime parts: [A000607](https://oeis.org/A000607)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -89,7 +89,11 @@
"\n",
"## Relevant sequences\n",
"* Partition numbers: [A000041](https://oeis.org/A000041)\n",
"* Generalized pentagonal numbers: [A001318](https://oeis.org/A001318)"
"* Generalized pentagonal numbers: [A001318](https://oeis.org/A001318)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -61,6 +61,16 @@
"\n",
"tuple(ts.static_order())"
]
},
{
"cell_type": "markdown",
"id": "242e35e6",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -81,7 +81,11 @@
"source": [
"If you want to go the extra mile, there are several [algorithms for computing square roots](https://en.wikipedia.org/wiki/Square_root_algorithms) that you can implement yourself, such as Heron's method, which is a special case of [Newton's method](https://en.wikipedia.org/wiki/Newton%27s_method) for solving $x^2 - n = 0$. The method works by starting with an initial estimate $x_0$ (such as $\\frac{n}{2}$), then repeatedly calculating\n",
"$$x_{k+1} = \\frac{1}{2}\\left(x_k + \\frac{n}{x_k}\\right)$$\n",
"until $|x_{k+1} - x_k|$ is sufficiently small. For computing the integer square root, this can be when $|x_{k+1} - x_k| < 1$."
"until $|x_{k+1} - x_k|$ is sufficiently small. For computing the integer square root, this can be when $|x_{k+1} - x_k| < 1$.\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -88,6 +88,16 @@
"source": [
"minimal_path_sum(mat)"
]
},
{
"cell_type": "markdown",
"id": "aff1f323",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -91,6 +91,16 @@
"source": [
"minimal_path_sum(mat)"
]
},
{
"cell_type": "markdown",
"id": "db7b11ca",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -90,6 +90,16 @@
"source": [
"minimal_path_sum(mat)"
]
},
{
"cell_type": "markdown",
"id": "f1685769",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -390,7 +390,11 @@
"id": "1c1cc8aa",
"metadata": {},
"source": [
"This gives our top squares as 10 (JAIL), 15 (R2), and 24 (E3)."
"This gives our top squares as 10 (JAIL), 15 (R2), and 24 (E3).\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -125,7 +125,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Number of rectangles in an $m \\times n$ grid: [A098358](https://oeis.org/A098358)"
"* Number of rectangles in an $m \\times n$ grid: [A098358](https://oeis.org/A098358)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -96,7 +96,11 @@
"source": [
"## Relevant sequences\n",
"* Number of pairs $a,b$ such that $(a+b)^2 + n^2$ is square: [A143714](https://oeis.org/A143714)\n",
"* Partial sums of A143714: [A143715](https://oeis.org/A143715)"
"* Partial sums of A143714: [A143715](https://oeis.org/A143715)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -80,7 +80,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Prime power triples: [A134657](https://oeis.org/A134657)"
"* Prime power triples: [A134657](https://oeis.org/A134657)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -104,7 +104,11 @@
"source": [
"## Relevant sequences\n",
"* Minimal product-sum numbers: [A104173](https://oeis.org/A104173)\n",
"* Set sizes $k$ with a minimal product-sum number of $2k$: [A033179](https://oeis.org/A033179)"
"* Set sizes $k$ with a minimal product-sum number of $2k$: [A033179](https://oeis.org/A033179)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -162,6 +162,16 @@
"\n",
"total"
]
},
{
"cell_type": "markdown",
"id": "109ecfb2",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -116,6 +116,16 @@
"source": [
"len(arrangements)"
]
},
{
"cell_type": "markdown",
"id": "7229398d",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -64,7 +64,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Answers for limits of 0, 1, 2, ...: [A155154](https://oeis.org/A155154)"
"* Answers for limits of 0, 1, 2, ...: [A155154](https://oeis.org/A155154)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -109,7 +109,11 @@
"metadata": {},
"source": [
"## Related sequences\n",
"* Numbers we iterate over: [A009994](https://oeis.org/A009994)"
"* Numbers we iterate over: [A009994](https://oeis.org/A009994)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -133,7 +133,11 @@
"metadata": {},
"source": [
"## Relevant sequences\n",
"* Catalan numbers: [A000108](https://oeis.org/A000108)"
"* Catalan numbers: [A000108](https://oeis.org/A000108)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -29,11 +29,11 @@
{
"data": {
"text/plain": [
"[-1/3*(780*sqrt(3) + 1351)^t*(56*sqrt(3) + 97) + 1/3*(-780*sqrt(3) + 1351)^t*(56*sqrt(3) - 97) - 1/3,\n",
"[-1/3*(780*sqrt(3) + 1351)^t*(4*sqrt(3) + 7) + 1/3*(-780*sqrt(3) + 1351)^t*(4*sqrt(3) - 7) - 1/3,\n",
" -1/3*(780*sqrt(3) + 1351)^t*(56*sqrt(3) + 97) + 1/3*(-780*sqrt(3) + 1351)^t*(56*sqrt(3) - 97) - 1/3,\n",
" -1/3*(780*sqrt(3) + 1351)^t*(780*sqrt(3) + 1351) + 1/3*(-780*sqrt(3) + 1351)^t*(780*sqrt(3) - 1351) - 1/3,\n",
" -1/3*(780*sqrt(3) + 1351)^t*(4*sqrt(3) + 7) + 1/3*(-780*sqrt(3) + 1351)^t*(4*sqrt(3) - 7) - 1/3,\n",
" 1/3*(780*sqrt(3) + 1351)^t*(sqrt(3) + 2) - 1/3*(-780*sqrt(3) + 1351)^t*(sqrt(3) - 2) - 1/3,\n",
" 1/3*(780*sqrt(3) + 1351)^t*(209*sqrt(3) + 362) - 1/3*(-780*sqrt(3) + 1351)^t*(209*sqrt(3) - 362) - 1/3,\n",
" 1/3*(780*sqrt(3) + 1351)^t*(sqrt(3) + 2) - 1/3*(-780*sqrt(3) + 1351)^t*(sqrt(3) - 2) - 1/3,\n",
" 1/3*(780*sqrt(3) + 1351)^t*(15*sqrt(3) + 26) - 1/3*(-780*sqrt(3) + 1351)^t*(15*sqrt(3) - 26) - 1/3]"
]
},
@ -169,7 +169,11 @@
"## Relevant sequences\n",
"* Side lengths in the first case: [A103772](https://oeis.org/A103772)\n",
"* Side lengths in the second case: [A103974](https://oeis.org/A103974)\n",
"* The union of the two cases: [A120893](https://oeis.org/A120893)"
"* The union of the two cases: [A120893](https://oeis.org/A120893)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -82,7 +82,11 @@
"\n",
"## Relevant sequences\n",
"* Smallest members of amicable chains: [A003416](https://oeis.org/A003416)\n",
"* The amicable chain containing this problem's answer: [A072890](https://oeis.org/A072890)"
"* The amicable chain containing this problem's answer: [A072890](https://oeis.org/A072890)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -326,7 +326,11 @@
"\n",
"Algorithm X can be made more efficient by applying a property Knuth named [dancing links](https://en.wikipedia.org/wiki/Dancing_Links). This concept boils down to the fact you can efficiently re-add a previously removed node to a [doubly linked list](https://en.wikipedia.org/wiki/Doubly_linked_list).\n",
"\n",
"By creating a special data structure ([shown here](https://commons.wikimedia.org/wiki/File:Dancing_links.svg)) that takes advantage of this property, you can create a very efficient implementation of Algorithm X. Such an implementation is deemed DLX, and *this* is the default algorithm that SageMath uses in its Sudoku solver."
"By creating a special data structure ([shown here](https://commons.wikimedia.org/wiki/File:Dancing_links.svg)) that takes advantage of this property, you can create a very efficient implementation of Algorithm X. Such an implementation is deemed DLX, and *this* is the default algorithm that SageMath uses in its Sudoku solver.\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],

View File

@ -31,6 +31,16 @@
"modulus = 10^10\n",
"(28433 * pow(2, 7830457, modulus) + 1) % modulus"
]
},
{
"cell_type": "markdown",
"id": "0454e1f8",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

View File

@ -268,6 +268,16 @@
"source": [
"max(max_squares.values())"
]
},
{
"cell_type": "markdown",
"id": "69a1b066",
"metadata": {},
"source": [
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
]
}
],
"metadata": {

Some files were not shown because too many files have changed in this diff Show More