Pure Python implementations of competitive programming algorithms.
CKP is a Python library providing various algorithms for solving competitive programming problems.
Here’s a simple code for computing sum of all prime numbers under $10^7$:
from ckp.number_theory import PrimeSieve
# Prints "3203324994356".
print(sum(PrimeSieve(10_000_000).primes()))
CKP is not yet on PyPI, so you need to get CKP from GitHub.
pip install git+https://github.com/123jimin/ckp.git
I recommend using Poetry to manage Python packages.
poetry add git+https://github.com/123jimin/ckp.git
Below is the list of submodules CKP provides. Click on a header to check API available under the module.
It’s generally preferred to import one or more of the sub-packages, rather than doing import ... from ckp
.
ckp.number_theory
Contains various functions related to number theory, mostly for working on a finite field $\mathbb{F}_p$.
ckp.linear_algebra
ckp.string
ckp.data_structure
ckp.graph_theory
Note: graph data structures themselves are under ckp.data_structure.graph
, not under this module.
ckp.graph_theory.tree
ckp.fourier
Contains various functions for discrete Fourier transformation (DFT).
ckp.automata
Contains algorithms related to finite-state automata.
ckp.geometry
Contains various algorithms and functions for 2D and 3D geometry.
ckp.numeric
Contains various constants and algorithms for computing numeric functions.
ckp.nimber
Contains nimber arithmetic, which is just an another name for the Galois field $GF(2^{2^k})$.
ckp.misc
Contains several niche algorithms that aren’t used much.
Following algorithms are not implemented in CKP, mostly because the Python Standard Library already provides an implementation.
functools.cache
.graphlib.TopologicalSorter
.math.erf
and math.erfc
.math.gamma
and math.lgamma
.
ckp.data_structure.sorted_containers
.Many parts of CKP are work-in-progress.
There’s no guarantee on API stability. No backwards compatibility is provided.
Using CKP for purposes other than competitive programming is not recommended. Consider using another library, implementing your own C extension, or using another language.
CKP is licensed under the MIT license: https://github.com/123jimin/ckp/blob/main/LICENSE
ckp.data_structure.sorted_containers
: also check https://github.com/grantjenks/python-sortedcontainers/blob/master/LICENSE.ckp.geometry.delaunay
: also check https://github.com/mkirc/delaunay/blob/main/LICENSE.