Skip to main content

Math and Competitive Programming utilities for Python

Project description

cp_math_utils

A comprehensive Python library offering essential mathematical and competitive programming utilities. Includes number theory functions, data structures, graph algorithms, string helpers, and more — all designed to be efficient and easy to use.


Features

  • Modular arithmetic utilities (GCD, LCM, Modular Exponentiation, Inverse mod, Chinese Remainder Theorem)
  • Prime testing (optimized and normal)
  • Sieve of Eratosthenes for prime generation
  • Data structures: Segment Trees, Fenwick Trees, Disjoint Set Union (Union-Find)
  • Graph utilities: BFS, DFS, Reverse Graph (Transpose), shortest paths
  • String utilities: KMP algorithm, Z-algorithm, palindrome checks
  • Competitive programming helpers: direction vectors, sliding window maximum/minimum, prefix sums, frequency counters
  • Well documented with time and space complexities

Installation

You can install the package via pip:

pip install cp-math-utils

Or clone this repo and install manually:

git clone https://github.com/mohankumarkadiri/cp-math-utils.git
cd cp-math-utils
pip install .

Examples

Prime Check & Modular Exponentiation

from cp_math_utils import math_utils

print(math_utils.is_prime_optimized(101))        # True
print(math_utils.mod_exp(2, 10, 1000))           # 24

Neighboring Cells (Grid Movement)

from cp_math_utils import helpers

for nx, ny in helpers.neighbors(1, 1, 3, 3):
    print(nx, ny)
# Outputs: (0, 1), (1, 0), (1, 2), (2, 1)

Using Segment Tree

from cp_math_utils.ds import SegmentTree

arr = [1, 3, 5, 7, 9, 11]
st = SegmentTree(arr)
print(st.query(1, 3))  # Sum from index 1 to 3
st.update(1, 10)       # Update index 1 to value 10
print(st.query(1, 3))

Documentation

Each module and function is documented with:

  • Clear description
  • Time and space complexity

🔗 License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cp-math-utils-1.0.0.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cp_math_utils-1.0.0-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file cp-math-utils-1.0.0.tar.gz.

File metadata

  • Download URL: cp-math-utils-1.0.0.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for cp-math-utils-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0676907e3fd73cce262b9d0605bb33e8d9a9edfddc2e2ce0894531b0f30fabdb
MD5 b0fdfc8de37d6f16c57e6c5fb73a95dc
BLAKE2b-256 e050128e8cae669a8eeeed8c0224a23511761362788c36ee5d82e21e09748464

See more details on using hashes here.

File details

Details for the file cp_math_utils-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: cp_math_utils-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for cp_math_utils-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fc341df9354fd086779b6a79074f6182c726ac5a19ac18d8bd627616c499fce0
MD5 6413481c541b517ec68857d62eebc7b0
BLAKE2b-256 3afc3c030a4f5f1708678dd6e6dcdfbb69146672e6baa3efd5314a3528732e16

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page