
gcd
Let $gcd(a,b)=left( a, bright)=r$
Then $a=pr, b=qr, a pmod b=a-kb=pr-kqr mid r$
$Rightarrow gcd(a,b) = gcd(b, a%b)$
Then we prove that the gcd is max gcd.(Oh, my poor English.)
There are two ways to prove it.
First Way:
Presume that $r$ is the maxium gcd(a,b), and $r$ is different from $r’$ which is the maxium $gcd(b, a% b)$.
It means $r > r’$.
$a=pr, b=qr, a% b=pr-kqr$
$rmid b, rmid (a% b), r>r’$
so $r$ is maxium $gcd(b, a% b)$, it’s against to the condition which we presumed.
so $r$ is the maxium $gcd(a, b)$ and $gcd(a, a% b)$.
Second Way:
Let set $A$ be all factor of $gcd(a, b)$, and let set $B$ be all factor of $gcd(b, a% b)$.
-
if $din A$, $a=pd, b=qd, a% b=pd-kqd$
so $dmid (a% b), din B$ -
if $din B$, $b=pd, a% b=qd, a=kqd + pd$
so $d mid a, din A$
It means $A=B$, so $gcd(a,b)_{max}=gcd(b, a% b)_{max}$
1 |
def (a, b): |
1 |
int (int a, int b) { |
exgcd
1 |
def exgcd(a, b): |
1 |
int exgcd(int a, int b, int &x, int &y) { |




近期评论