内容:

\(gcd(a,b)=gcd(b,a\% b)\)

用途:

这不废话嘛,当然是用来求最大公约数啊

证明:(这还是四月份的时候cdx巨佬给我讲的qwq)

\(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);
}

谢谢收看,祝身体健康!

相关文章:

  • 2021-10-06
  • 2022-01-01
  • 2021-11-05
  • 2022-02-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-15
  • 2021-07-20
  • 2021-08-18
  • 2021-05-21
  • 2022-01-13
  • 2022-12-23
相关资源
相似解决方案