Number theory is a branch of pure mathematics that studies the properties and relationships of integers. It is one of the oldest and most abstract areas of mathematics (so no need to be panic when there's something incomprehensible), yet it has significant applications in modern fields like cryptography, computer science, and coding theory.
Part 1: Divisibility and GCD
Definition: the ability of being completely divided without any reminder. (整除)
Explain: there are a apples, which need to be given to b people. As result, everyone has the same number of apples and no apple left.
Examples: 4 % 2 = 0
There is no remainder on division
Notation b∣a
b is a divisor/factor of a
a is divisible by b
Division Algorithm
In mathematics, when division is "not exact" or "doesn't divide evenly," it means that in integer division, the division operation does not result in a whole number; instead, there is a non-zero remainder. Well, if the integer cannot be completely divided, and the result seems like this:
dd0=q ... r
Or in another way:
d0=d⋅q+r
.
Where:
d0 is the dividend, the number that is being divided.
d is the divisor, the number by which the dividend is divided.
q is the quotient, which is an integer;
r is the remainder, and it satisfies 0≤r<b;
For example: if a=10 and b=3, then: 10=3⋅3+1.
If the purpose is to calculate the reminder of a being divided by b, then:
d0modd=rd0≡r(modd)
.
Greatest Common Divisor
Greatest Common Divisor (GCD): The greatest common divisor of a and b, i.e., gcd(a,b), is the largest integer that divides both a and b.
GCD, in other words, it’s the largest number that both (or all) numbers share as a factor.
There is a case that in real world utilizing GCD:
Imagine you have two pieces of rope, one 12 meters long and the other 18 meters long, and you want to cut them into the largest possible equal lengths. The GCD helps here. For 12 and 18 meters, the GCD is 6 meters, so you can cut both ropes into segments that are 6 meters long.
Euclidean Algorithm
The Euclidean algorithm works by repeatedly applying the relation:
gcd(a,b)=gcd(b,amodb)
.
The process continues until the remainder becomes 0, at which point the GCD is the last non-zero remainder.
In detail:
a=b⋅q+rb=r⋅q1+r1r=r1⋅q2+r2...
.
Until meet the 0:
rn−2=rn−1⋅qn+0
.
Example: divide 48 by 18 and find the remainder:
48=18⋅2+1218=12⋅1+612=6⋅2+0∴GCD(48,18)=6
.
And then, it can be represented in form of a⋅x+b⋅y=gcd(a,b)
Which is: GCD(48,18)=48⋅(−1)+18⋅3=6
In this case, x=−1 and y=3
Part 2: Modular Arithmetic
The modulus
Definition: If a is an integer and b is a positive integer, we define amodb to be the remainder when a is divided by b; the integer b is called the modulus.
Thus, for any integer a:
a=b⋅q+r,0≤r<b;q=[a|b]a=[a|b]⋅b+(amodb)
.
Congruent modulo
Definition: Two integers a and b are said to be congruent modulo n if (amodn)=(bmodn), which can be written as:
a≡b(modn)
≡: This symbol represents congruence. It indicates that the two values are equivalent in terms of their remainders when divided by n.
(modn): This notation means "modulo n." It specifies the modulus, which is the divisor n.
Note 1: if a≡0(modn), then n|a.
Note 2: if gcd(a,n)=1, a⋅x≡a⋅y(modn), then x≡y(modn)
Why gcd(a,n)=1, a⋅x≡a⋅y(modn), then x≡y(modn)?
Proof:
∵a⋅x≡a⋅y(modn)∴a⋅x−a⋅y≡0(modn)∴a(x−y)≡0(modn)∴a(x−y)is a multiple of n∴a(x−y)=q⋅n,where q is a integer.∴x−y=aq⋅n,where all numbers are integers∴x−ymust be an integer andaq⋅nmust be an integer as well∵a and n are coprime,a does not divide n∴q must be a multiple of a,oraq⋅nwon’t be an integerletqnew=q∣a∴(x−y)modn=qnew⋅nmodn=0∴x−y≡0(modn)x≡y(modn)
Modular Inverse
In modular arithmetic, instead of working with division (which can be problematic in modular systems), we use multiplication to "undo" the effect of a number. The modular inverse of a modulo n is a number x such that:
a⋅x≡1(modn)a⋅a−1≡1(modn),a−1just for present and a−1=a1at here
There exists a modular inverse for a mod b if a is relatively prime to b
Proof: If gcd(a,b)=1, then a has a modular inverse modulo b
∵gcd(a,b)=1∴a⋅x+b⋅y=1(Using Bezout’s Identity)∴a⋅x+b⋅y≡1(modb)∵b⋅yis a multiple ofb∴b⋅y≡0(modb)∴a⋅x≡1(modb)∴a⋅a−1≡1(modn)
Arithmetic Modulo 8
Ever unit in this table represents (x+y)mod8, such as in (1,1), (1+1)mod8=2.
+
0
1
2
3
4
5
6
7
0
0
1
2
3
4
5
6
7
1
1
2
3
4
5
6
7
0
2
2
3
4
5
6
7
0
1
3
3
4
5
6
7
0
1
2
4
4
5
6
7
0
1
2
3
5
5
6
7
0
1
2
3
4
6
6
7
0
1
2
3
4
5
7
7
0
1
2
3
4
5
6
Multiplication Modulo 8
Ever unit in this table represents (x⋅y)mod8, such as in (1,1), (1⋅1)mod8=1.
×
0
1
2
3
4
5
6
7
0
0
0
0
0
0
0
0
0
1
0
1
2
3
4
5
6
7
2
0
2
4
6
0
2
4
6
3
0
3
6
1
4
7
2
5
4
0
4
0
4
0
4
0
4
5
0
5
2
7
4
1
6
3
6
0
6
4
2
0
6
4
2
7
0
7
6
5
4
3
2
1
Additive and Multiplicative Inverse Modulo 8
Col.
0
1
2
3
4
5
6
7
w
0
1
2
3
4
5
6
7
−w
0
7
6
5
4
3
2
1
w−1
-
1
-
3
-
5
-
7
Column w: These are the elements (integers) from 0 to 7, which are taken modulo 8.
Column −w : These represent the additive inverses modulo 8. For each number w, its additive inverse is the number that, when added to w, results in 0 modulo 8. For example: 1+7=8≡0mod8, so the additive inverse of 1 is 7.
Column w−1 : These represent the multiplicative inverses modulo 8. The multiplicative inverse of a number w is the number x such that w⋅x≡1mod8. For example: The multiplicative inverse of 1 is 1, as 1⋅1=1mod8.
Bezout's Identity
For any two integers a and b, there exist integers x and y such that:
a⋅x+b⋅y=GCD(a,b)
Example: To calculate the modular inverse of 911 mod 999.
leta=911andb=999;According to Euclidean algorithm:L1:999=1⋅911+88L2:911=10⋅88+31L3:88=2⋅31+26L4:31=1⋅26+5L5:26=5⋅5+1∴gcd(a,b)=1Then, Tracing backward:Begin with L5:1=26–5⋅5Substitute L4 to replace 5:1=26–5⋅(31–1⋅26)=−5⋅31+6⋅26Substitute L3 to replace 26:1=−5⋅31+6⋅(88–2⋅31)=6⋅88–17⋅31Substitute L2 to replace 31:1=6⋅88–17⋅(911–10⋅88)=−17⋅911+176⋅88Substitute L1 to replace 88:1=−17⋅911+176⋅(999–1⋅911)=176⋅999–193⋅911∴gcd(911,999)=1=−193⋅911+176⋅999Modular reduction: 1(mod999)=−193⋅911+176⋅999(mod999)Result: 1≡806⋅911(mod999)∴806 is the modular inverse of 911 modulo 999.
Part 3: Prime Number, Fermat’s Theorem and Euler’s Theorem
Prime Number
Prime numbers only have divisors of 1 and itself.
Composite number has at least one divisor other than 1 and itself
The fundamental theorem of arithmetic: Any integer a,a>1 can be factored in a unique way as: a=p1a1⋅p2a2⋅...⋅ptat where p1<p2<...<pt are prime numbers and where each ai is a positive integer. For example: 24=2⋅2⋅2⋅3=23⋅31
Fermat's Theorem
If p is prime and a is a positive integer not divisible by p then:
For a positive integer n, Euler's Totient Function ϕ(n) is defined as the number of integers from 1 to n that are coprime to n. Two integers are coprime if their greatest common divisor (gcd) is 1.
Basic Property:
ϕ(n)=∣{k∣1≤k≤n,gcd(k,n)=1}∣
For a Prime Numberp: If p is a prime number, then every number from 1 to p−1 is coprime with p. Therefore:
ϕ(p)=p−1
For p=7, a prime number:ϕ(7)=7−1=6
The numbers from 1 to 6 (i.e., 1, 2, 3, 4, 5, 6) are all coprime with 7.
It is used in Euler's Theorem, which generalizes Fermat's Little Theorem. For any integer a and n where a is coprime to n:
ap−1≡1(modp)aϕ(p)≡1(modp)Fermat’s Little Theorem
General Formula:
The general formula for Euler's Totient Function ϕ(n), where n is expressed as a product of distinct prime factors, is given by:
ϕ(n)=n(1−p11)(1−p21)⋯(1−pm1)
where n can be expressed as:
n=p1k1⋅p2k2⋯pmkm
and p1,p2,…,pm are distinct prime numbers.
For n=30, Factorize 30=2⋅3⋅5
Therefore, ϕ(30)=30(1−21)(1−31)(1−51)=8
Thus, ϕ(30)=8, meaning there are 8 numbers from 1 to 30 that are coprime with 30.
If n=pk (p is prime), then ϕ(n)=pk−pk−1
Proof:
ϕ(n)=n(1−p11)(1−p21)⋯(1−pm1)
If n=pk (p is prime), there is only one prime factor p with exponent k. Thus:
Part 4: Efficient Modulo Operation for Large Numbers
Chinese Remainder Theorem
The Chinese Remainder Theorem (CRT) is a fundamental result in number theory that provides a method for solving systems of simultaneous congruences with pairwise coprime moduli. It ensures that there is a unique solution to such systems, and this solution is congruent modulo the product of the moduli.
Theorem
Let n1,n2,…,nk be pairwise coprime positive integers, and let a1,a2,…,ak be integers. Then there exists a unique integer x modulo N=n1⋅n2⋯nk such that:
x≡ai(modni)for i=1,2,…,k
Define the Problem:
We want to find an integer x that satisfies:
x≡ai(modni)
for each i, where ni are pairwise coprime.
Construct the Solution:
Let N=n1⋅n2⋯nk. For each i:
Define Ni=niN.
Find Mi such that Ni⋅Mi≡1(modni). This can be done using the Extended Euclidean Algorithm to find the modular inverse of Ni modulo ni.
Formulate the Solution:
The solution can be expressed as:
x=i=1∑kai⋅Ni⋅Mi
Verify the Solution:
Check that x satisfies all congruences:
x≡ai(modni)
for all i.
Uniqueness:
The solution x is unique modulo N because the moduli are pairwise coprime, ensuring that the solution within the range 0 to N−1 is unique.
Consider the following system of congruences:
⎩⎨⎧x≡2(mod3)x≡3(mod4)x≡2(mod5)
Calculate N:N=3⋅4⋅5=60
Compute Ni and Mi:
For n1=3: N1=360=20
Find M1 such that 20⋅M1≡1(mod3).
Here, M1=2 (since 20⋅2≡40≡1(mod3)).
For n2=4: N2=460=15
Find M2 such that 15⋅M2≡1(mod4).
Here, M2=3 (since 15⋅3≡45≡1(mod4)).
For n3=5: N3=560=12
Find M3 such that 12⋅M3≡1(mod5).
Here, M3=3 (since 12⋅3≡36≡1(mod5)).
Calculate x:
x=2⋅20⋅2+3⋅15⋅3+2⋅12⋅3=80+135+72=287
Reduce x modulo 60:
x≡287(mod60)≡47
Thus, x=47 is a solution to the system of congruences.