Discrete Mathematics for CS
2019-03-30
2019-03-30
2.2 Inverses and Greatest Common Divisors
Lemma 2.8
The equation
$$ a{\cdot}_nx = 1 $$
has a solution in $\mathbb{Z}_{n}$ if and only there exist integers $x$ and $y$ such that
$$ ax + ny = 1 $$
Corollary 2.10
If $a\in\mathbb{Z}_{n}$ and $x$ and $y$ are integers such that $ax + ny = 1$, then the multiplicative inverse of $a$ in $\mathbb{Z}_{n}$ is $x$ mod $n$
Lemma 2.11
Given $a$ and $n$, if there exist integers $x$ and $y$ such that $ax+ny=1$, then $\gcd(a,n)=1$
Lemma 2.13
If $j,k,q$, and $r$ are positive integers such that $k=jq+r$, then
$$ \gcd(j,k) = \gcd(r,j) $$
Euclid’s extended GCD algorithm
- 本书版
void gcd_cs(int j, int k, int ans[3])// j < k(为什么?)且j, k为正数 |
- 算法导论版
void gcd_tc(int a, int b, int ans[3]) |
Theorem 2.15
Two positive integers $j$ and $k$ have greatest common divisor 1 iff there are integers $x$ and $y$ such that $hx+ky=1$