MIDDLE_SCHOOL_GCD(m,n)
- L1 ← PrimeFactorization(m)
- L2 ← PrimeFactorization(n)
- L3 ← FindCommonFactors(L1, L2)
- GCD ← 1
- for i ← 0 to sizeof L3-1
- GCD ← GCD * L3[i]
- return GCD
PrimeFactorization(n)
- L ← []
- tmp ← n
- for each prime p where p < sqrt(n) do
- while tmp%p = 0 do
- L.append(p)
- tmp ← tmp/p
- return L
SIEVE(n)
- A ← []
- L ← []
- for i ← 2 to n do
- A.pushback(i)
- for p ← 2 to sqrt(n) do
- if A[i] ≠ 0 then
- j ← p * p
- while j ≤ n do
- A[j] ← 0
- j ← j + p
- for i ← 2 to n do
- if A[i] ≠ 0 then
- L.pushback(i)
- return L
CONSECUTIVE(m,n)
- p ← min(m,n)
- if m = 0 then
- return n
- if n = 0 then
- return m
- while m%p ≠ 0 and n%p ≠ 0 do
- p ← p - 1
- return p
Euclid(m,n)
- while n ≠ 0 do
- r ← m % n
- m ← n
- n ← r
- return m