mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 18:52:02 +00:00
P1082 [NOIP2012 提高组] 同余方程
R45973301
This commit is contained in:
parent
144492f9d4
commit
c7bacc1ac7
25
Luogu/problem/P1082/P1082.cpp
Normal file
25
Luogu/problem/P1082/P1082.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int exgcd(int a, int b, int& x, int& y) {
|
||||||
|
if (!b) {
|
||||||
|
x = 1;
|
||||||
|
y = 0;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
int d = exgcd(b, a % b, x, y);
|
||||||
|
int t = x;
|
||||||
|
x = y;
|
||||||
|
y = t - (a / b) * y;
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int a, b, x = 0, y = 0;
|
||||||
|
cin >> a >> b;
|
||||||
|
exgcd(a, b, x, y);
|
||||||
|
x = (x % b + b) % b;
|
||||||
|
cout << x << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user