Files
teamnote/2025fall/source/Math/Diophantos.cpp
2026-06-03 09:36:52 +09:00

12 lines
264 B
C++

pll diophantos(ll a, ll b) {
assert(a>0 and b>=0);
if(b == 0) return {1, 0};
auto [y, x] = diophantos(b, a%b); y = y-(a/b)*x;
if(x < 0 or x >= b) {
ll t = x/b;
if(x%b < 0) t--;
x -= b*t; y += a*t;
}
return {x, y};
}