Skip to content

Number theory

This section is currently under construction. Use the search bar to find the topic you are looking for.

Number theory basics

Notations
  • aba \mid b - aa divides bb
  • aZa \Z - the set of all integers that are multiples of aa

Divisibility

GCD - Greatest Common Divisor

The greatest common divisor of two integers aa and bb is the largest integer that divides both aa and bb:

aZ+bZ=gcd(a,b)Z a \Z + b \Z = \gcd(a, b) \Z

This can be extended to more than two integers. When gcd(a,b)=1\gcd(a, b) = 1, we say that aa and bb are coprime.

We also have the following properties:
gcd(a,b)=gcd(b,a)\gcd(a, b) = \gcd(b, a)
gcd(a,b)=gcd(a,b)=gcd(a,b)=gcd(a,b)\gcd(a, b) = \gcd(-a, b) = \gcd(a, -b) = \gcd(-a, -b)
gcd(a,b)=gcd(a,ba)\gcd(a, b) = \gcd(a, b - a)
gcd(a,b)=gcd(a,bmoda)\gcd(a, b) = \gcd(a, b \mod a)
gcd(ka,kb)=kgcd(a,b)\gcd(k \cdot a, k \cdot b) = k \cdot \gcd(a, b)

Bezout's identity

For any a1,a2anZa_1, a_2 \cdots a_n \in \Z, they are coprime if and only if there exist integers x1,x2xnx_1, x_2 \cdots x_n such that:

x1a1+x2a2++xnan=1 x_1 \cdot a_1 + x_2 \cdot a_2 + \cdots + x_n \cdot a_n = 1
Gauss's lemma
If abca \mid bc and gcd(a,b)=1\gcd(a, b) = 1, then aca \mid c.
LCM - Least Common Multiple

The least common multiple of two integers aa and bb is the smallest integer that is a multiple of both aa and bb:

aZbZ=lcm(a,b)Z a \Z \cap b \Z = \text{lcm}(a, b) \Z

This can be extended to more than two integers. We also have the following properties: lcm(a,b)=lcm(b,a)\text{lcm}(a, b) = \text{lcm}(b, a)
lcm(a,b)=lcm(a,b)=lcm(a,b)=lcm(a,b)\text{lcm}(a, b) = \text{lcm}(-a, b) = \text{lcm}(a, -b) = \text{lcm}(-a, -b)
lcm(a,b)=lcm(a,ba)\text{lcm}(a, b) = \text{lcm}(a, b - a)
lcm(a,b)=lcm(a,bmoda)\text{lcm}(a, b) = \text{lcm}(a, b \mod a)
lcm(ka,kb)=klcm(a,b)\text{lcm}(k \cdot a, k \cdot b) = k \cdot \text{lcm}(a, b)
lcm(a,b)gcd(a,b)=ab\text{lcm}(a, b) \cdot \gcd(a, b) = \mid a \cdot b \mid

Prime numbers

Prime number
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Fundamental theorem of arithmetic

Every integer greater than 1 can be expressed uniquely as a product of prime numbers.

n=p1e1p2e2pkek n = p_1^{e_1} \cdot p_2^{e_2} \cdots p_k^{e_k}
Fermat's little theorem

If pp is a prime number and aa is an integer not divisible by pp, then:

ap11modp a^{p-1} \equiv 1 \mod p
Wilson's theorem

A natural number pp is a prime number if and only if:

(p1)!1modp (p-1)! \equiv -1 \mod p

Euler’s totient function

Euler's totient function

The Euler’s totient function ϕ(n)\phi(n) is the number of positive integers less than nn that are coprime to nn.

ϕ(n)={kN1k<n,gcd(k,n)=1} \phi(n) = \mid \lbrace k \in \N \mid 1 \leq k < n, \gcd(k, n) = 1 \rbrace \mid
Euler's totient function properties
  • If pp is a prime number, then ϕ(p)=p1\phi(p) = p - 1
  • If aa and bb are coprime, then ϕ(ab)=ϕ(a)ϕ(b)\phi(a \cdot b) = \phi(a) \cdot \phi(b)
  • If pp is a prime number and kNk \in \N, then ϕ(pk)=pkpk1\phi(p^k) = p^k - p^{k-1}
Euler's theorem

If aa and nn are coprime, then:

aϕ(n)1modn a^{\phi(n)} \equiv 1 \mod n

Tricks

  • Recovering a base from two coprime powers with Bézout

    If you can obtain two powers ge1g^{e_1} and ge2g^{e_2} of the same unknown base gg with coprime exponents (gcd(e1,e2)=1\gcd(e_1, e_2) = 1), you can recover gg itself even without being able to invert the exponentiation (no root, no discrete log needed). Bézout’s identity gives integers u,vu, v such that ue1+ve2=1u e_1 + v e_2 = 1, hence:

    g=gue1+ve2=(ge1)u(ge2)vg = g^{u e_1 + v e_2} = (g^{e_1})^u \cdot (g^{e_2})^v

    This works in any group (integers mod nn, matrices, elliptic curve points), and is typical against an oracle that exponentiates a chosen base by a secret (but coprime between calls) exponent. The exponents u,vu, v come from the extended Euclidean algorithm (xgcd in SageMath).