From 1372178916d45a367a88740a564d17d98c455c92 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 21 Apr 2022 19:23:01 +0800 Subject: [PATCH] =?UTF-8?q?876.=20=E5=BF=AB=E9=80=9F=E5=B9=82=E6=B1=82?= =?UTF-8?q?=E9=80=86=E5=85=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acwing.com/problem/content/submission/code_detail/13591616/ --- AcWing/876/876.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 AcWing/876/876.cpp diff --git a/AcWing/876/876.cpp b/AcWing/876/876.cpp new file mode 100644 index 00000000..bebf14c9 --- /dev/null +++ b/AcWing/876/876.cpp @@ -0,0 +1,35 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +int n, a, p; + +long long binpow(int a, int b, int m) { + long long res = 1; + a %= m; + while (b) { + if (b & 1) res = res * a % m; + a = 1ll * a * a % m; + b >>= 1; + } + return res; +} + +int main() { + std::ios::sync_with_stdio(false); + + cin >> n; + + while (n--) { + cin >> a >> p; + if (a % p) { + cout << binpow(a, p - 2, p) << endl; + } else { + cout << "impossible" << endl; + } + } + + return 0; +}