Extended Euler's theorem
When \ (gcd (a, m) = 1 \) when Euler's theorem is
Behind the two conditions \ (GCD \) No, attention \ (C \) and \ (\ phi (m) \ ) Relationship
\(Description\)
Seeking \ (2 ^ {2 ^ {
2 ^ {2 ^ {\ cdots}}}} (mod p) \) simplified for the sake \ (x \ equiv 2 ^ x (mod p)) \)
\(Solution\)
Since \ (2 ^ {2 ^ {
2 ^ {2 ^ {\ cdots}}}}> \ phi (p) \) and \ (\ phi (p) \ ) shrinking, so with the third formula i.e. can be
used (ans (p) \) \ expressed (P \) \ modulo answer, apparently \ (ans (p) = 2 ^ {ans (\ phi (p)) + \ phi (p)} \)
\ (\ phi (p) \ ) shrinking until it is \ (1 \) , then any number \ (MOD 1 = 0 \) , it reaches the boundary of the recursive return \ (0 \) to
\(Code\)
#include <cstdio>
#define int long long
typedef long long ll;
const int N = 1e7+71;
int p_(ll x, int y, int z) {
int ret = 1;
for (; y; (x *= x) %= z, y >>= 1) if (y & 1) (ret *= x) %= z;
return ret;
}
signed phi[N];
ll solve(int p) {
if (p == 1) return 0;
return p_(2, solve(phi[p]) + phi[p], p);
}
int t, p;
signed main() {
phi[1] = 1;
for (signed i = 2; i < N; i++) if (!phi[i]) {
for (signed j = i; j < N; j += i) {
if (!phi[j]) phi[j] = j;
phi[j] = phi[j] / i * (i-1);
}
}
for (scanf("%lld", &t); t--; ) {
scanf("%lld", &p);
printf("%lld\n", solve(p));
}
}