I. Equations, inequalities and expressions

14. Divisibility and primes

The app factors a whole number on its own into primes – it divides by the smallest primes one after another and writes 360 = 2³·3²·5; for a prime it shows that no prime up to its square root divides it. You can also write the test as isprime(97).

The greatest common divisor gcd(60, 90) and the least common multiple lcm(18, 30) come from the prime factorizations, or with the “Euclidean algorithm” chip by division with a remainder. The extended Euclidean algorithm with its table gives Bézout’s identity bezout(240, 46): gcd(240, 46) = 240·u + 46·v.

A number's divisors divisors(36) come in pairs 1·36, 2·18, … up to the square root, their count checked by the factorization. The divisibility rules divisibility(1236) form a table for 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 and 25 (the last digit, the digit sum, the alternating sum…); one divisor is written divisibility(1236, 7), as the sentence “is 1236 divisible by 7” or 7 | 1236 – a divisor without a school rule is divided with a remainder. The primes up to 200 come from the sieve of Eratosthenes (“primes up to 50”). A linear equation ax + by = c in the integers (“3x + 5y = 1, x, y ∈ ℤ” or the ℤ chip) is solved by Bézout's identity – all the solutions x = x₀ + 5k, y = y₀ − 3k.

Modular arithmetic: the remainder 17 mod 5, the inverse 3^(-1) mod 11 (from the extended Euclidean algorithm, with a check) and the power 7^13 mod 13 by repeated squaring. RSA is built on them – rsa(p = 11, q = 13, e = 7, m = 9) computes n, φ(n), the private key d, then encrypts the message and decrypts it again; e and m may be left out.

How to enter it

360, factor(360), isprime(97)The prime factorization, a primality test.
gcd(60, 90), lcm(18, 30)The greatest common divisor and the least common multiple.
divisors(36), divisibility(1236), divisibility(1236, 7)A number's divisors and the divisibility rules – all, or one divisor (also the sentence “is 1236 divisible by 7”, 7 | 1236).
primes up to 50The primes up to n (at most 200) by the sieve of Eratosthenes; also primes(50).
3x + 5y = 1, x, y ∈ ℤA linear equation in the integers (Diophantine); also diophantine(3, 5, 1).
bezout(240, 46)Bézout’s identity.
17 mod 5, 3^(-1) mod 11, 7^13 mod 13The remainder, the inverse and the power modulo n.
rsa(p = 11, q = 13, e = 7, m = 9)RSA with small numbers.

Examples

The prime factorization by successive division.
Input: 360
360
A prime – no divisor up to the square root.
Input: 97
97
The gcd from the prime factorizations.
Input: gcd(60, 90)
NSD(60, 90)
The lcm via the gcd by the Euclidean algorithm.
Input: lcm(60, 90) Euclidean algorithm
NSN(60, 90)
The divisors in pairs, their count from the factorization.
Input: dělitelé(36)
dělitelé(36)
The table of divisibility rules.
Input: dělitelnost(1236)
dělitelnost(1236)
Divisibility by seven – cutting off the last digit.
Input: dělitelnost(1309, 7)
dělitelnost(1309, 7)
The sieve of Eratosthenes.
Input: prvočísla do 50
prvočísla do 50
Bézout’s identity by the extended Euclidean algorithm.
Input: bezout(240, 46)
bezout(240, 46)
A Diophantine equation by Bézout's identity.
Input: 3x + 5y = 1, x, y ∈ ℤ
3x + 5y = 1, x, y ∈ ℤ
A power modulo n by repeated squaring.
Input: 7^13 mod 13
7^13 mod 13
RSA – the keys, encryption and decryption.
Input: rsa(p = 11, q = 13, e = 7, m = 9)
rsa(p = 11, q = 13, e = 7, m = 9)
rsa(p = 11, q = 13, e = 7, m = 9)rsa(p = 11, q = 13, e = 7, m = 9)

Known limitations