A small number theory utility library (gcd, primes, modular arithmetic, CRT, etc.)
Project description
numbertheory
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 numbertheory
Or from source for development:
pip install -e .[test]
Usage
from numbertheory 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pynumbertheory-0.1.0.tar.gz
(4.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pynumbertheory-0.1.0.tar.gz.
File metadata
- Download URL: pynumbertheory-0.1.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75f2de05946e8e5e70545db2b7fff3669943c99afd022e5e7b3c4e22a2b4f950
|
|
| MD5 |
edb6a0f240c2def3e17c646ac89372d5
|
|
| BLAKE2b-256 |
69638900d76fa629e970638d63b3ebad97d67468fdedcae64691b9ebcbcc8bb5
|
File details
Details for the file pynumbertheory-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pynumbertheory-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9682ac7ae475a02009f10e0fcad3876374b6d19e2c4d2ab103433094e3b9851b
|
|
| MD5 |
a5f385ea0da4661fb09aeb70c9c4cba7
|
|
| BLAKE2b-256 |
9d74905edd869aa33d9757d2a6fd152c2a5e82755fc9effc80a20be44d49494c
|