extGcd

a*T[0]+b*T[1]=T[2], T[2]=gcd

T[3]
extGcd
(
T
)
(
in T a
,
in T b
)
if (
!isIntegral!T ||
isSigned!T
)

Examples

1 import std.numeric : gcd;
2 foreach (i; 0..100) {
3     foreach (j; 0..100) {
4         auto e = extGcd(i, j);
5         assert(e[2] == gcd(i, j));
6         assert(e[0] * i + e[1] * j == e[2]);
7     }
8 }

Meta