Number theory
Arbitrary-precision integer tools — primality, factorisation, divisor functions, GCD and modular arithmetic, the Chinese remainder theorem, bases, repeating decimals, continued fractions, big factorials, and Roman numerals.
Added · updated 14 October 2026
How to use it
All integer work uses exact arbitrary-size integers (BigInt). Inputs accept decimal, 0x, 0b, and 0o literals with _ separators.
-
Primes & factors: Miller–Rabin primality (deterministic below 3.3 × 1024, probabilistic above), factorisation by trial division and Pollard’s rho, τ, σ, φ, μ, ω, and Ω, all divisors, the neighbouring primes, and a sieve listing primes up to 20 million.
-
GCD & modular: gcd and lcm with Bézout coefficients, modular exponentiation and inverse, and solving a·x ≡ b (mod m). The Chinese remainder theorem accepts one congruence per line (
2 mod 3) and handles moduli that are not coprime. -
Bases & fractions: any base from 2 to 36; fractions to decimals with the repeating part in brackets (
1/7 = 0.(142857)) and back; continued fractions and best rational approximations (π → 22/7, 355/113…). -
Big numbers: exact n!, C(n, r), P(n, r), Fibonacci numbers by fast doubling, 2n, and Catalan numbers.
-
Roman numerals: both directions, 1–3999.
Factorising numbers whose two largest prime factors are both beyond about 20 digits can exceed the four-second limit.
Sharing
Share link (under the title) copies a URL that reopens this tool exactly as you have it — every tab’s inputs, with the current tab selected. Opening such a link replaces the inputs this browser had saved for the tool.
Linking to an example
Companion to chapters 1, 2 and 23 (numbers, fractions and decimals, number theory) of
Mathematics, Reconnected. Each input box has a short
parameter, and the tab comes from the # part of the address, for example
/tools/numbers/?a=1071&b=462#gcd or
?frac=1/7#bases. Share link writes the same parameters.
| Tab | Parameter | Meaning | Example |
|---|---|---|---|
|
|
integer to test and factorise |
|
|
|
list the primes up to this |
|
|
|
gcd, lcm and Bézout coefficients of a and b |
|
|
|
modulus and exponent: a mod m, aᵉ mod m, a⁻¹ mod m, and a·x ≡ b |
|
|
|
congruences |
|
|
|
a number written in base |
|
|
|
a fraction to a repeating decimal, or a repeating decimal back ( |
|
|
|
best rational approximations of a real number ( |
|
|
|
n!, C(n, r), P(n, r), Fibonacci, 2ⁿ and Catalan for n = |
|
|
|
a number or Roman numeral |
|
|
one of the presets below (it also picks the tab); other parameters override it |
|
Presets:
-
ch01-base-explorer— 255 in bases 2, 8, 10, 16 and more -
ch01-sqrt2-approximations— Best fractions for √2: 7/5, 17/12, 41/29, … -
ch01-factor-explorer— Factorise 360, with its divisors -
ch02-repeating-1-7— 1/7 = 0.(142857), period 6 -
ch02-repeating-1-17— 1/17 has the maximum period, 16 -
ch02-recurring-36— 0.(36) back to a fraction: 4/11 -
ch02-recurring-16— 0.1(6) back to a fraction: 1/6 -
ch03-square-and-multiply— 3^1000000 mod 1,000,000,007 by square-and-multiply -
ch23-is-391-prime— Is 391 prime? 17 × 23 -
ch23-sieve-30— The primes up to 30 -
ch23-sieve-400— The primes up to 400 (the 20 × 20 sieve) -
ch23-gcd-1071-462— gcd(1071, 462) = 21 = 7·462 − 3·1071 -
ch23-lcm-252-198— gcd and lcm of 252 and 198 -
ch23-jugs-3-5— Jugs of 3 and 5: gcd 1, so 4 gallons is reachable (Bézout) -
ch23-inverse-7-mod-26— 7⁻¹ mod 26 = 15 -
ch23-fermat-3-100-mod-7— 3¹⁰⁰ mod 7 = 4 -
ch23-modpow-7-13-mod-11— 7¹³ mod 11 = 2 by square-and-multiply -
ch23-diffie-hellman— Diffie–Hellman: 5⁶ mod 23 = 8 -
ch23-rsa-private-key— RSA with p = 5, q = 11: d = 3⁻¹ mod 40 = 27 -
ch23-rsa-decrypt— RSA: decrypt 13²⁷ mod 55 = 7 -
ch23-crt— Chinese remainder theorem: x ≡ 2 (mod 3), 3 (mod 5), 2 (mod 7)
Feedback is a gift. Something to improve, a feature to add, or a bug? Tell me.
Runs entirely in your browser; nothing you type leaves this page.