标签:ref for turn span code bec == The therefore
\(gcd(a,b)=gcd(b,a\% b)\)
这不废话嘛,当然是用来求最大公约数啊
设\(d=gcd(a.b)\)
则有\(a=md,b=nd\), \(\Rightarrow\) \(a-b=(m-n)d\)
\(\because\) \(m\)与\(n\)互质
\(\therefore\) \((m-n)\)与\(n\)互质
\(\therefore\) \(gcd((m-n)d,nd)=d\)即\(gcd(a-b,b)=d\)
\(\therefore\) \(gcd(a,b)=gcd(a-b,b)\)
\(\therefore\) \(gcd(a,b)=gcd(a\%b,b)\)
关于为什么\(m-n\)与\(n\)互质:
证明:假设\(m-n\)不与\(n\)互质,有\(gcd(m-n,n)=p,p\neq 1\)
则\(m-n=xp,n=yp\)
\(\therefore\) \(m=(x+y)p\)
\(\therefore\) \(a=md=(x+y)pd,b=nd=ypd\)
\(\therefore\) \(a,b\)有公约数\(pd\)
$\because $ \(gcd(a,b)=d\)
\(\therefore\) \(p=1\)与假设矛盾
故\(m-n\)与\(n\)互质
Code:
int gcd(int x, int y) {
return y == 0 ? x : gcd(y, x % y);
}
谢谢收看,祝身体健康!
标签:ref for turn span code bec == The therefore
原文地址:https://www.cnblogs.com/yanxiujie/p/11723844.html