0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:11:58 +00:00

3884. 上帝与集合的正确用法

https://darkbzoj.cc/submission/191438
This commit is contained in:
Baoshuo Ren 2022-05-11 18:04:55 +08:00
parent 56435b1c0a
commit acdb922081
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

43
BZOJ/3884/3884.cpp Normal file
View File

@ -0,0 +1,43 @@
#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;
}