目录
GCD(Greatest Common Divisor)最大公因数
Euclidean GCD Algorithm(扩展欧几里得算法)
Fundamental Theorem of Arithmetic(算数基本定理)
𝐷𝑒𝑓𝑖𝑛𝑖𝑡𝑖𝑜𝑛
GCD(Greatest Common Divisor)最大公因数
If 𝑎 and 𝑏 are not both 0, then 𝑔𝑐𝑑 𝑎, 𝑏 or 𝑎, 𝑏 is the greatest common divisor
of 𝑎 and 𝑏.
Coprime(互质)
If gcd(a,b)=1, then 𝑎 and 𝑏 are coprime.
5 and 9 are coprime
5 and 10 are not coprime
引入
从一个基本的证明入手,运用反证法的思想
Theorem :2 is an irrational number
自然数的基本性质
1.Successor Operation
𝑠 𝑛 = 𝑛 + 1 (类似于一个数由前一个数+1所得)
2.PMI (Principle of Mathematical Induction) 数学归纳法
𝑝 1 is true and 𝑝 𝑛 ⇒ 𝑝 𝑛 + 1 , then 𝑝 𝑛 is true for all natural numbers.
3. WOP (Well Ordering Principle) 良序原则
Every nonempty subset of natural number has a smallest element.
Divisibility(整除)
Division with Remainder(带余除法)
𝑇ℎ𝑒𝑜𝑟𝑒𝑚 1: Given 𝑎, 𝑏 ∈ 𝑍 with 𝑎 > 0, ∃𝑞, 𝑟 ∈ 𝑍, such that 𝑏 = 𝑎𝑞 + 𝑟,0 ≤ 𝑟 < 𝑎
简而言之就是两数相除,q为除法的整数部分,r为除法的余数部分(但是r>=0,不能<0)
例如:
311 =23×13+12 此时q = 23,r = 12,符合要求
−21 =(-1)× 11+(-10) 此时q = -1,r = -10,不符合要求
那么需要修改成−21 =(-2)× 11+1 此时q = -2,r = 1,符合要求
如果要证明就得用到前面的良序原则了
𝑇ℎ𝑒𝑜𝑟𝑒𝑚 2. Let 𝑔 = 𝑔𝑐𝑑 (𝑎, 𝑏) , then ∃x0, y0 ∈ 𝑍 such that 𝑔 = 𝑎x0 + 𝑏y0.
其实这就是裴蜀定理,已知整数a、b,在求得a、b的最大公约数同时,能找到整数x、y(其中一个很可能是负数),使它们等式ax+by = gcd(a,b)
𝐶𝑜𝑟𝑜𝑙𝑙𝑎𝑟𝑦: If 𝑔𝑐𝑑 𝑎, 𝑚 = 1 and 𝑔𝑐𝑑 𝑏, 𝑚 = 1, then 𝑔𝑐𝑑 𝑎𝑏, 𝑚 = 1.
𝐶𝑜𝑟𝑜𝑙𝑙𝑎𝑟𝑦: If 𝑐|𝑎𝑏 and 𝑔𝑐𝑑 𝑐, 𝑎 = 1, then 𝑐|𝑏.
这些推论比较直观就不加以证明了
接着说一说一个比较实用的算法
Euclidean GCD Algorithm(扩展欧几里得算法)
该算法又称为辗转相除法,编程中常用递归方法实现
核心思想是gcd(a,b)==gcd(a%b,a)
在纸上手算一下,这里我对调了一下顺序方便看,gcd(b,a)==gcd(a,a%b)
关于为什么gcd(a,b)==gcd(a%b,a)?
当然了,平常编程时写的代码是这样的
int gcd(int a,int b)
{
return b? gcd(b,a%b):a;
}
为什么gcd(a,b)==gcd(b,a%b),我从计算机专业的角度证明了下,如果不严谨数院dalao不要骂我
Fundamental Theorem of Arithmetic(算数基本定理)
Every positive integer can be written as a product of primes (possibly with repetion) and any such expression is unique up to a permutation of the prime factors.