Definition
An integer a divides an integer b (written a∣b) if there exists an integer k such that:
b=ak
We say a is a divisor or factor of b, and b is a multiple of a.
If a∤b, then a does not divide b.
Basic Properties
For all integers a,b,c:
- a∣0 (every integer divides 0)
- 1∣a (1 divides every integer)
- If a∣b and b∣c, then a∣c (transitivity)
- If a∣b and a∣c, then a∣(b+c) and a∣(b−c)
- If a∣b, then a∣bc for any integer c
- If a∣b and a∣c, then a∣(mb+nc) for any integers m,n
For positive integers:
If a∣b and b=0, then ∣a∣≤∣b∣.
Division Algorithm
For any integers a and d with d>0, there exist unique integers q (quotient) and r (remainder) such that:
a=dq+rwhere 0≤r<d
Notation
- a÷d=q (integer division)
- amodd=r (remainder)
Examples
- 17=5×3+2, so 17÷5=3 and 17mod5=2
- −17=5×(−4)+3, so −17÷5=−4 and −17mod5=3
Greatest Common Divisor (GCD)
The greatest common divisor of a and b, written gcd(a,b) or (a,b), is the largest positive integer that divides both.
Properties
gcd(a,b)=gcd(b,a)
gcd(a,0)=∣a∣
gcd(a,b)=gcd(a−b,b)=gcd(amodb,b)
gcd(a,b)=gcd(a,b−a)
Coprime (Relatively Prime)
a and b are coprime if gcd(a,b)=1.
Euclidean Algorithm
Efficiently computes gcd(a,b) using repeated division.
Algorithm
gcd(a, b):
while b ≠ 0:
r = a mod b
a = b
b = r
return a
Example
gcd(252,105)
252=105×2+42
105=42×2+21
42=21×2+0
gcd(252,105)=21
Time Complexity
O(log(min(a,b))) divisions
Extended Euclidean Algorithm
Finds integers x and y such that:
gcd(a,b)=ax+by
Bézout's Identity
For any integers a and b (not both zero), there exist integers x and y such that:
gcd(a,b)=ax+by
Example
Find x,y such that gcd(252,105)=252x+105y
Working backwards:
21=105−42×2
21=105−(252−105×2)×2
21=105×5−252×2
21=252×(−2)+105×5
So x=−2, y=5.
Least Common Multiple (LCM)
The least common multiple of a and b, written lcm(a,b) or [a,b], is the smallest positive integer divisible by both.
Relationship to GCD
gcd(a,b)×lcm(a,b)=∣ab∣
lcm(a,b)=gcd(a,b)∣ab∣
Properties
lcm(a,b)=lcm(b,a)
lcm(a,1)=∣a∣
lcm(a,a)=∣a∣
Divisibility Rules
| Divisor | Rule |
|---|
| 2 | Last digit is even |
| 3 | Sum of digits divisible by 3 |
| 4 | Last two digits form number divisible by 4 |
| 5 | Last digit is 0 or 5 |
| 6 | Divisible by both 2 and 3 |
| 8 | Last three digits divisible by 8 |
| 9 | Sum of digits divisible by 9 |
| 10 | Last digit is 0 |
| 11 | Alternating sum of digits divisible by 11 |
Linear Diophantine Equations
Equation of the form: ax+by=c
Solvability
Has integer solutions if and only if gcd(a,b)∣c.
Finding Solutions
- Find particular solution (x0,y0) using extended Euclidean algorithm
- General solution:
x=x0+dbt,y=y0−dat
where d=gcd(a,b) and t∈Z.