2014年2月6日 星期四

[數論] 歐拉定理 (Euler's theorem)、Wilson's theorem

參考資料
http://www.math.cornell.edu/~putnam/modular.pdf
http://www.millersville.edu/~bikenaga/number-theory/euler/euler.html (推薦)

Euler's theorem
定義 aφ(n)1(modn), 其中 φ(n) 是 Euler's phi function, (a,n)=1.

證明:內容擷自下面兩段 YouTube 影片, 雖然影片是證明費馬小定理, 但仍不失一般性(費馬小定理是歐拉定理的特例.). 簡單來說, a mod n, 2a mod n, ..., (n-1)a mod n 的餘數的集合是 {1, 2, ..., n-1}. 例如a=3, n=5, (a, n)=1, 則 3 mod 5, 6 mod 5, ..., 12 mod 5 的餘數依序是 3, 1, 4, 2, 寫成集合是 {1, 2, 3, 4}.

我們得到式子 a2a...(n1)a12...(n1)(n1)! mod n
上式可改寫成 (n1)!an1(n1)! mod n.
將上式左右兩邊消去 (n1)!, 即得 an11 mod n. 證明完畢




Euler's theorem 可以簡化我們在計算某個數的高次方的餘數. 假設今天我們想知道 7222 除以 10 的餘數, 亦即 7222 的個位數字.

方法1. 算出 7222, 看個位數字. 這個方法很直觀, 若次方數字很小, 這個方法也許比較快, 但對於高次方, 例如這裡的 222, 顯然毫無效率可言.

方法2. 試圖看 7 的次方數中, 個位數字有無規律. 依序列出後會發現 7 的次方的個位數字會以 1,9,3,7 的順序出現, 每四個數循環一次. 所以我們把 222 除以循環週期 4, 得到餘數 2, 最後得到 7222 個位數字是 9. 這個方法很好用, 但遇到週期很長的題目, 甚至是看出不週期的時候, 這個方法就派不上用場.

如果知道 Euler's theorem, 我們就可以用第三種方法來解決這類問題.

方法3. 因為 (7,10)=1, 所以我們可以用 Euler's theorem. 因為 φ(10)=4, 所以我們知道 741(mod10). 接著再用方法2中, 看 222 除以 4 的餘數. 最後得到答案是 9

萬一....要是 an 不互質呢? 例如我把 7222 改成 8222, 那不就不能直接套用 Euler's theorem 嗎? 此時我們要對 n 做適當地分解.

因為 10=2×5, 所以我們分開求 8222 除以 28222 除以 5 的餘數. 82220(mod2); 另一方面, 因為 (8,5)=1, ϕ(5)=4, 由 Euler's theorem 得知 8φ(5)841(mod5), 而 222 除以 4 的餘數是 2, 所以 8222855×4+21×824(mod5). 最後得到答案是 4(why?).

Beacuse 8222=2a=5b+4, we know that b must be even. Let b=2c, then 5b+4=5(2c)+4=10c+4. Therefore, 82224(mod10).

練習題
試求 16198 的末兩位數字. (答案:96)


有一個跟 Euler's theorem 的類似的定理, 叫做 Wilson's theorem. 下面的證明擷自影片內容.
Wilson's theorem: p is prime iff (p1)!1 mod p.
<pf> If p is prime, and k{1,2,...,p1}, then there exists two integers a and b such that ak+bp=1(according to the Euclidean algorithm). We have ak+bpak1 (mod p). It says that the modular multiplicative inverse of k modulo p exists.

The point is to to pair each number with its modular inverse. There are two exceptions: k=1 and k=p1. The modular inverses of 1 and p-1 modulo p are equal to themselves (check: 1×11 mod p, (p1)(p1)1 mod p).

(p1)!1(221)(331)...(p1)p11 mod p. Q.E.D.


Note: 21 是指 2 的模反元素, 它會是 {2,3,...,p2} 的某個元素. 同理, 31 也會是 {2,3,...,p2} 的某個元素, 且 2131 不會相同, 不會有重複的問題. 下面是證明.

For two integers a,b{2,3,...,p2}. Assume a and b have the same modular multiplicative inverse modulo p, called k. akbk1 mod p.
akbk0 mod p
(ab)k0 mod p

Since k{2,3,...,p1}, (k,p)=1, (ab) must be a multiple of p. We know that a,b{2,3,...,p2}, 0(ab)<p. Therefore, a=b. Q.E.D.

[數論] 歐拉函數(Euler's Phi Function)

參考資料
EulerTheorem-Silverman http://palmer.wellesley.edu/~ivolic/pdf/Classes/USEM/EulerTheorem-Silverman.pdf

定義2 一個數論函數 f(n), 若 (m,n)=1, 具有性質 f(mn)=f(m)f(n), 則稱 f(n) 為「積性函數(multiplicative function)」. 若不論有無 (m,n)=1, 上式都成立, 則稱 f(n) 為「完全積性函數(complete multiplicative function)」.

例2 試證: hλ(n)=nλ(λ為常數)是完全積性函數.
<pf> 設 n=n1n2, 無論 n1n2 是否互質, 都有 hλ(n)=hλ(n1n2)=(n1n2)λ=(n1)λ(n2)λ=hλ(n1)hλ(n2). 由定義得知, h(n) 是完全積性函數.

性質2 若積性函數 f(n) 不恆等於 0, 則必有 f(1)=1.
<pf> 設 f(n)0. 因為 f(n) 為積性函數, 所以有 f(n)=f(n1)=f(n)f(1), 從而 f(1)=1.

定義3 小於或等於正整數 n 且與 n 互質的正整數個數稱為 n 的歐拉函數(Euler's function), 記為 φ(n).
  1. ϕ(1)=1
  2. n=p 是質數, 因為凡是小於 p 的正整數均與 p 互質, 故 φ(p)=p1.
  3. n=pk,kN, 亦即 n 是某個質數的次方. 凡是 p 的倍數都不列入. 這些 p 的倍數中, 最大的是 pk=pk1p, 故總共有 k1p 的倍數.(例如要知道 φ(27), 因為 27=33, 故有 3, 23, 33..., 323, 總共 323 的倍數.). 因此 ϕ(pk)=pkpk1=pk(11p).
  4. 對於一般正整數 N, 對 n 做質因數分解, 得到 N=pk11pk22...pknn. 則 ϕ(N)=ϕ(pk11pk22...pknn)=ϕ(pk11)ϕ(pk22)...ϕ(pknn) (這裡用到了 Euler's function 是積性函數的性質, 證明在文末).
公式:ϕ(N)=N(11p1)(11p2)...(11pn)

證明:Euler's function 是積性函數
<pf> If p and q are prime, then φ(pq)=(pq1)(q1)(p1)=pq(p+q)+1=(p1)(q1)=φ(p)ϕ(q).
(q1)p 的倍數的個數, (p1)q 的倍數的個數.



底下介紹一些歐拉函數的推廣.
Euler's theorem(當要對一個高次方的數取餘數)  http://en.wikipedia.org/wiki/Euler's_theorem
RSA加密演算法 http://en.wikipedia.org/wiki/Euler's_totient_function