teamnote history merge
This commit is contained in:
14
2024fall/source/Math/Diophantos.cpp
Normal file
14
2024fall/source/Math/Diophantos.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
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};
|
||||
}
|
||||
Reference in New Issue
Block a user