Skip to content

Commit cb2068b

Browse files
committed
add extgcd
1 parent 24e4c4b commit cb2068b

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ AtCoder解説放送ライブラリ集
2424
|名前|コード|説明|
2525
|:--|:--|:--|
2626
|GCD/LCM|[gcd.cpp](gcd.cpp)|最大公約数と最小公倍数|
27+
|extgcd|[extgcd.cpp](extgcd.cpp)|Ai+Bj=gcd(A,B)なるi,jを求める|
2728
|Combination|[comb.cpp](comb.cpp)|nCkをmod素数で求める|
2829
|Matrix|[mat.cpp](mat.cpp)|行列|
2930
|素数|[prime.cpp](prime.cpp)|素数列挙と素因数分解|

extgcd.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// ai+bj=g
2+
// https://youtu.be/fDJpXN2R75A?t=6895
3+
ll extgcd(ll a, ll b, ll& i, ll& j) {
4+
if (b == 0) { i = 1; j = 0; return a;}
5+
ll p = a/b, g = extgcd(b,a-b*p,j,i);
6+
j -= p*i;
7+
return g;
8+
}

0 commit comments

Comments
 (0)