0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-30 20:16:27 +00:00
OI-codes/Luogu/problem/P4139/P4139.cpp
2021-02-02 15:29:53 +08:00

44 lines
790 B
C++

#include <bits/stdc++.h>
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;
}