上帝与集合的正确用法
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll p,a2; ll euler(ll n) { ll res = n; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { res = res / i * (i - 1); while (n % i == 0) n = n / i; } } if (n > 1) res = res / n * (n - 1); return res; } ll pow_mod(ll a,ll b,ll p) { ll res = 1; while (b) { if (b & 1) res = res * a % p; b = b >> 1; a = a * a % p; } return res; } ll dfs(ll p) { if (p == 1) return 0; int np = euler(p); return pow_mod(a2, dfs(np) + np, p); } int main() { int _; scanf("%d", &_); while (_--) { scanf("%lld", &p); a2 = 2 % p; printf("%lld ", dfs(p)); } }