版本比较
笔记
标题
增加 1 行删除 1 行
11exgcd 笔记笔记正文
增加 9 行删除 49 行
11233455678791091011121314151617181920212223242526272829303132333435363738394041424344454647484950515253111213## exgcd$empty$
拓展gcdhttps://www.luogu.com.cn/record/292082989
给出 $a,b$ $$T(n)=2T(\sqrt{n})+O(\log n)$$
令 $a,b,x,y,d=\gcd(a,b)$令 $n=2^k$,则
则 $ax+by=d$ 必定有解
$bx_1+(a \mod b)y_1=d$
$ax+by=bx_1+(a \mod b)y_1$
$a \mod b=a-(a \div b) \times b$
$bx_1+(a \mod b)y_1=bx_1+(a-(a \div b) \times b)y_1$
$bx_1+(a-(a/b) \times b)y_1=bx_1+ay_1-(a \div b)by_1$
$bx_1+ay_1-(a/b)by_1=ay_1+b(x_1-(a \div b)y_1)$
:::info{code}```cpp#include <bits/stdc++.h>using namespace std;
void exgcd(const int &a,const int &b,int &x,int &y){ if(b){ exgcd(b,a%b,x,y); int tmp=y; y=(x-(a/b)*y); x=tmp; } else{ x=1; y=0; return; }}
int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int a,b,x,y; cin>>a>>b; exgcd(a,b,x,y); cout<<x<<" "<<y; return 0;}```:::$$T(2^k)=4T(2^{k/4})+2O(k)+O(k)$$