From acdb922081f9578b4c60806102939fd06a8c993a Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Wed, 11 May 2022 18:04:55 +0800 Subject: [PATCH] =?UTF-8?q?3884.=20=E4=B8=8A=E5=B8=9D=E4=B8=8E=E9=9B=86?= =?UTF-8?q?=E5=90=88=E7=9A=84=E6=AD=A3=E7=A1=AE=E7=94=A8=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://darkbzoj.cc/submission/191438 --- BZOJ/3884/3884.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 BZOJ/3884/3884.cpp diff --git a/BZOJ/3884/3884.cpp b/BZOJ/3884/3884.cpp new file mode 100644 index 00000000..2b4e2c77 --- /dev/null +++ b/BZOJ/3884/3884.cpp @@ -0,0 +1,43 @@ +#include + +using namespace std; + +long long phi(long long x) { + long long r = x; + for (long long i = 2; i * i <= x; i++) + if (x % i == 0) { + r = r / i * (i - 1); + while (x % i == 0) { + x /= i; + } + } + if (x > 1) { + r = r / x * (x - 1); + } + return r; +} + +long long pow(long long x, long long y, long long mod) { + long long r = 1; + while (y) { + if (y & 1) r = (r * x) % mod; + x = (x * x) % mod, y >>= 1; + } + return r; +} + +long long f(long long x) { + if (x == 1) return 0; + long long n = phi(x); + return pow(2, n + f(n), x); +} + +int main() { + long long t, x; + cin >> t; + while (t--) { + cin >> x; + cout << f(x) << endl; + } + return 0; +}