题意:https://www.lydsy.com/JudgeOnline/problem.php?id=3884
解法:反复使用扩展欧拉定理,递归求解。
https://www.cnblogs.com/812-xiao-wen/p/10500135.html
https://www.cnblogs.com/SovietPower/p/8353374.html
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #include <cstdio> #include <string> #include <stdio.h> #include <queue> #include <stack> #include <map> #include <set> #include <string.h> #include <vector> #define ME(x , y) memset(x , y , sizeof(x)) #define SF(n) scanf("%d" , &n) #define rep(i , n) for(int i = 0 ; i < n ; i ++) #define INF 0x3f3f3f3f #define mod 998244353 #define PI acos(-1) using namespace std; typedef long long ll ; ll quickpow(ll a , ll b , ll mo) { ll ans = 1; while(b) { if(b&1) ans = ans * a % mo ; b >>= 1 ; a = a * a % mo ; } return ans % mo ; } ll get_phi(ll n) { ll res = n ; for(int i = 2 ; i * i <= n ; i++) { if(n%i == 0) { res -= res / i ; while(n % i == 0) { n /= i; } } } if(n > 1) res -= res / n ; return res ; } ll solve(ll n) { if(n == 1) return 0 ; ll t = get_phi(n); return quickpow(2 , solve(t)+t , n); } int main() { int t ; scanf("%d" , &t); while(t--) { ll p ; scanf("%lld" , &p); cout << solve(p) << endl; } return 0 ; }