跳到正文

个人记录

exgcd

ProzacPainkiller约 1 分钟
原文
文章信息与版本

文章信息

发布
2022年2月23日
收录
2026年11月17日
更新
2026年11月17日
篇幅
约 1 分钟

版本

  1. v1当前
设整数 x 和 y 使得 ax+by=gcd⁡(a,b),求 x,y\text{设整数 }x\text{ 和 }y\text{ 使得 }ax+by=\gcd(a,b),\text{求 } x,y
设 a′=b,b′=a mod b,x′,y′,使得 a′x′+b′y′=d\text{设 }a'=b,b'=a\text{ mod } b,x',y',\text{使得 }a'x'+b'y'=d 当 b′=0 时,可得 a′=gcd⁡(a,b)\text{当 }b'=0\text{ 时},\text{可得 }a'=\gcd(a,b) ∴此时 x′=1,y′=0\therefore\text{此时 }x'=1,y'=0
a′x′+b′y′=da'x'+b'y'=d ∴bx′+(a mod b)y′=d\therefore bx'+(a\text{ mod }b)y'=d ∴bx′+(a−b[a/b])y′=d\therefore bx'+(a-b[a/b])y'=d ∴bx′+ay′−b[a/b]y′=d\therefore bx'+ay'-b[a/b]y'=d ∴ay′+b(x′−[a/b]y′)=d\therefore ay'+b(x'-[a/b]y')=d ∴x=y′,y=x′−[a/b]y′\therefore x=y',y=x'-[a/b]y'
原文