mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 03:31:59 +00:00
203. 同余方程
https://www.acwing.com/problem/content/submission/code_detail/13560716/
This commit is contained in:
parent
7d50a57e6f
commit
bda3a10622
32
AcWing/203/203.cpp
Normal file
32
AcWing/203/203.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include <iostream>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
int a, b, x, y;
|
||||
|
||||
int exgcd(int a, int b, int &x, int &y) {
|
||||
if (!b) {
|
||||
x = 1;
|
||||
y = 0;
|
||||
return a;
|
||||
}
|
||||
|
||||
int g = exgcd(b, a % b, y, x);
|
||||
y -= a / b * x;
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
|
||||
cin >> a >> b;
|
||||
|
||||
exgcd(a, b, x, y);
|
||||
|
||||
cout << (x % b + b) % b << endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user