From bda3a10622770a15328a8679ce2b296b167c8c16 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Wed, 20 Apr 2022 16:25:06 +0800 Subject: [PATCH] =?UTF-8?q?203.=20=E5=90=8C=E4=BD=99=E6=96=B9=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acwing.com/problem/content/submission/code_detail/13560716/ --- AcWing/203/203.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 AcWing/203/203.cpp diff --git a/AcWing/203/203.cpp b/AcWing/203/203.cpp new file mode 100644 index 00000000..6717c7e9 --- /dev/null +++ b/AcWing/203/203.cpp @@ -0,0 +1,32 @@ +#include + +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; +}