← Back to the calculator

Number theory in CALCULA

The Number theory field works on integers: divisibility, primes, congruences. Results are exact, with no rounding.

GCD, LCM and prime factors

gcd(a, b) · lcm(a, b) = a · b

The GCD (greatest common divisor) comes from Euclid's algorithm: replace the larger number by its remainder in the division by the smaller one, until the remainder is zero. Every integer > 1 factors uniquely into primes.

Example

60 = 2²·3·5 and 84 = 2²·3·7. Their GCD is 2²·3 = 12, their LCM is 2²·3·5·7 = 420. Check: 12 × 420 = 5040 = 60 × 84.

Modular arithmetic

a ≡ b (mod n)   means   n divides (a − b)

Working “modulo n” means keeping only the remainder of the division by n — the arithmetic of the clock (13:00 ≡ 1:00, mod 12). It sits at the heart of cryptography and of checksums.

Example

Which weekday in 100 days? 100 mod 7 = 2: move forward two days. Fermat's little theorem and modular exponentiation, used in RSA, are also computed in CALCULA.

Typing it into CALCULA

“≡” menu → number theory: enter the integers, choose the operation (GCD, LCM, factorisation, primality test, modular power, modular inverse). See also conversions for number bases.