码迷,mamicode.com
首页 > 其他好文 > 详细

欧拉定理模板

时间:2019-03-18 11:57:53      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:sign   stream   names   set   push   res   sys   world   The   

//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\n", x)
#define outld(x) printf("%lld\n", 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;
}

 

欧拉定理模板

标签:sign   stream   names   set   push   res   sys   world   The   

原文地址:https://www.cnblogs.com/Eterna-King/p/10551041.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!