You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
474 B
26 lines
474 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
typedef long long LL;
|
|
|
|
// P1082 [NOIP2012 提高组] 同余方程
|
|
|
|
//扩展欧几里得
|
|
LL exgcd(LL a, LL b, LL &x, LL &y) {
|
|
if (!b) {
|
|
x = 1, y = 0;
|
|
return a;
|
|
}
|
|
LL d = exgcd(b, a % b, y, x);
|
|
y -= a / b * x;
|
|
return d;
|
|
}
|
|
|
|
int main() {
|
|
LL a, b;
|
|
scanf("%lld %lld", &a, &b);
|
|
LL x, y;
|
|
exgcd(a, b, x, y);
|
|
printf("%d\n", (x % b + b) % b);
|
|
return 0;
|
|
} |