https://github.com/shadikhasan/pynumbertheory
A lightweight Python library providing number theory utilities including GCD, LCM, primes, modular arithmetic, and the Chinese Remainder Theorem.
https://github.com/shadikhasan/pynumbertheory
algorithms math-library mathematics modular-arithmetic number-theory primes
Last synced: about 1 month ago
JSON representation
A lightweight Python library providing number theory utilities including GCD, LCM, primes, modular arithmetic, and the Chinese Remainder Theorem.
- Host: GitHub
- URL: https://github.com/shadikhasan/pynumbertheory
- Owner: shadikhasan
- Created: 2025-11-24T08:26:07.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2025-11-24T08:47:28.000Z (6 months ago)
- Last Synced: 2025-12-26T15:34:37.068Z (5 months ago)
- Topics: algorithms, math-library, mathematics, modular-arithmetic, number-theory, primes
- Language: Python
- Homepage: https://pypi.org/project/pynumbertheory/
- Size: 6.84 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
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+.
```bash
pip install pynumbertheory
```
Or from source for development:
```bash
pip install -e .[test]
```
Usage
-----
```python
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
-------
```bash
python -m pytest
```
License
-------
MIT