降幂公式

Codeforces - Power Tower

萝らか妹 提交于 2020-02-07 23:32:23
题目链接: Codeforces - Power Tower 可以注意到欧拉函数下降的速度是很快的,很快就能到1。所以暴力降幂即可。 注意快速幂的时候也需要降幂。因为如果快速幂中途出现了>=MOD的情况我们要加上MOD,以满足欧拉降幂的公式。 AC: # pragma GCC optimize("-Ofast","-funroll-all-loops") # include <bits/stdc++.h> # define int long long using namespace std ; const int N = 1e5 + 10 ; int n , m , phi [ 100 ] , a [ N ] ; int get ( int x ) { int res = x ; for ( int i = 2 ; i * i <= x ; i ++ ) { if ( x % i == 0 ) { res = res / i * ( i - 1 ) ; while ( x % i == 0 ) x / = i ; } } if ( x > 1 ) res = res / x * ( x - 1 ) ; return res ; } inline int mod ( int x , int p ) { return x >= p ? x % p + p : x ; } inline