Skip to main content

pynumbertheory

Compact, classroom-friendly number theory helpers for Python projects and scripts.

Features

  • Basic arithmetic: gcd, lcm, extended_gcd, is_perfect_square
  • Primes: is_prime, sieve, prime_factors
  • Modular arithmetic: mod_pow (fast exponentiation), mod_inv, chinese_remainder

Installation

Requires Python 3.9+.

pip install pynumbertheory

Or from source for development:

pip install -e .[test]

Usage

from pynumbertheory import (
    gcd, lcm, extended_gcd, is_perfect_square,
    is_prime, sieve, prime_factors,
    mod_pow, mod_inv, chinese_remainder,
)

gcd(12, 18)                      # 6
is_prime(97)                     # True
sieve(20)                        # [2, 3, 5, 7, 11, 13, 17, 19]
prime_factors(60)                # [2, 2, 3, 5]
mod_pow(2, 10, 1000)             # 24
mod_inv(3, 11)                   # 4
chinese_remainder([2, 3, 2], [3, 5, 7])  # 23

Testing

python -m pytest

License

MIT

Metadata

Release files for pynumbertheory 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pynumbertheory 0.1.1
File Size Uploaded
pynumbertheory-0.1.1.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pynumbertheory 0.1.1
File Interpreter ABI Platform
pynumbertheory-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.9 kB

Release files / pynumbertheory-0.1.1.tar.gz

Download URL pynumbertheory-0.1.1.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
09ffcca91702de7c6cf830cb6dccf772119368a5608539c43333cf3851292e83
BLAKE2b-256 checksum
How to use checksums
b47b28d6ebf4682d114562e31eb3e67158fd8b44f2eb64032714cc28586668f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Release files / pynumbertheory-0.1.1-py3-none-any.whl

Download URL pynumbertheory-0.1.1-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
709c16069cf12febd8cbcbbddba15c4d37f745e2953f7e8560288e9b23c23f71
BLAKE2b-256 checksum
How to use checksums
6b567a514b9dd070d1e36fe521614ced759d9e72a93607fa7b65bbe043c27a2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page