欧拉定理模板
Posted eterna-king
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了欧拉定理模板相关的知识,希望对你有一定的参考价值。
//author Eterna #define Hello the_cruel_world! #pragma GCC optimize(2) #include<iostream> #include<algorithm> #include<cstdio> #include<string> #include<cstring> #include<vector> #include<map> #include<set> #include<queue> #include<stack> #include<utility> #include<cmath> #include<climits> #include<deque> #include<functional> #include<complex> #include<numeric> #include<unordered_map> #define max(x,y) ((x)>(y)?(x):(y)) #define min(x,y) ((x)<(y)?(x):(y)) #define Pi acos(-1.0) #define ABS(x) ((x) >= 0 ? (x) : (-(x))) #define pb(x) push_back(x) #define lowbit(x) (x & -x) #define FRIN freopen("C:\Users\Administrator.MACHENI-KA32LTP\Desktop\in.txt", "r", stdin) #define FROUT freopen("C:\Users\Administrator.MACHENI-KA32LTP\Desktop\out.txt", "w", stdout) #define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define outd(x) printf("%d ", x) #define outld(x) printf("%lld ", x) #define il inline using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; const int maxn = 1e6; const int INF = 0x7fffffff; const int mod = 1e9 + 7; const double eps = 1e-7; inline int read_int(ll m) { bool flag = false; char c; int ret = 0, sgn = 1; do { c = getchar(); } while ((c < ‘0‘ || c > ‘9‘) && c != ‘-‘); if (c == ‘-‘) sgn = -1; else ret = c - ‘0‘; while ((c = getchar()) >= ‘0‘ && c <= ‘9‘) { ret = ret * 10 + (c - ‘0‘); if (ret >= m) ret %= m, flag = true; } return sgn * ret + m * (int)flag; } inline ll read_ll() { char c; ll ret = 0, sgn = 1; do { c = getchar(); } while ((c < ‘0‘ || c > ‘9‘) && c != ‘-‘); if (c == ‘-‘) sgn = -1; else ret = c - ‘0‘; while ((c = getchar()) >= ‘0‘ && c <= ‘9‘) ret = ret * 10 + (c - ‘0‘); return sgn * ret; } int prime[maxn + 5], cnt; bool is_prime[maxn + 5]; void init(int n) { for (int i = 2; i <= n; ++i)is_prime[i] = true; for (int i = 2; i <= n; ++i) { if (is_prime[i]) prime[++cnt] = i; for (int j = 1; j <= cnt && i * prime[j] <= n; ++j) { is_prime[i * prime[j]] = false; if (i % prime[j] == 0)break; } } } ll phi(ll x) { for (int i = 1; i <= cnt; ++i) if (x % prime[i] == 0)x = x / (prime[i]) * (prime[i] - 1); return x; } ll n, m, b; ll Quick_pow(ll base, ll index, ll p) { ll res = 1; while (index) { if (index & 1) res = res * base % p; base = base * base % p; index >>= 1; } return res % p; } int main() { init(maxn); cin >> n >> m; int p = phi(m); b = read_int(p); cout << Quick_pow(n % m, b, m) << endl; //system("pause"); return 0; }
以上是关于欧拉定理模板的主要内容,如果未能解决你的问题,请参考以下文章