标签:work 算法 公倍数 复杂度 turn mod 扩展欧几里得 扩展 公约数
#define ll long long
ll ksm(ll a, ll b, ll p) {
ll c = 1 % p;
a %= p;
while (b) {
if (b & 1) c = c * a % p;
a = a * a % p;
b >>= 1;
}
return c;
}
ll gcd(ll a, ll b) {
return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b) {
return a * b / gcd(a, b);
}
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1;
y = 0;
return a;
}
ll d = exgcd(b, a % b, x, y), z = x;
x = y;
y = z - a / b * y;
return d;
}
ll work(ll a, ll b, ll c) {
ll x, y, d = exgcd(a, b, x, y);
if (c % d) return -1;
return c / d * x;
}
标签:work 算法 公倍数 复杂度 turn mod 扩展欧几里得 扩展 公约数
原文地址:https://www.cnblogs.com/xht37/p/10217406.html