zoukankan      html  css  js  c++  java
  • 模板 欧拉定理

    #include<iostream>
    #include<string>
    #include<cmath>
    #include<cstring>
    #include<vector>
    #include<map>
    #include<set>
    #include<algorithm>
    #include<queue>
    #include<stack>
    #include<list>
    #include<sstream>
    #include<cstdio>
    #define INF 0x3f3f3f3f
    const int maxn = 1e6 + 5;
    const double PI = acos(-1.0);
    typedef long long ll;
    typedef unsigned long long ull;
    using namespace std;
    
    ll a, b, m;
    
    inline ll read(ll m) {
        register ll x = 0, f = 0;
        char ch = getchar();
        while (!isdigit(ch)) ch = getchar();
        while (isdigit(ch)) {
            x = x * 10 + ch - '0';
            if (x >= m) f = 1;
            x %= m, ch = getchar();
        }
        return x + (f == 1 ? m : 0);
    }
    
    ll euler_phi(ll n) {
        ll m = ll(sqrt(n + 0.5));
        ll ans = n;
        for (int i = 2; i <= m; i++) {
            if (n % i == 0) {
                ans = ans / i * (i - 1);
                while (n % i == 0) n /= i;
            }
        }
        if (n > 1) ans = ans / n * (n - 1);
        return ans;
    }
    
    ll quickPower(ll a, ll b, ll m) {   //计算a的b次方
        ll ans = 1;
        ll base = a;
        while (b) {
            if (b & 1) {
                ans *= base;
                ans %= m;
            }
            base *= base;
            base %= m;
            b >>= 1;   //注意是b>>=1 not b>>1
        }
        return ans;
    }
    
    int main() {
        scanf("%lld%lld", &a, &m);
        b = read(euler_phi(m));
        printf("%lld\n", quickPower(a, b, m));
        return 0;
    }
    View Code
  • 相关阅读:
    iOS开发UI篇—xib的简单使用
    iOS开发UI篇—字典转模型
    iOS开发UI篇—九宫格坐标计算
    iOS开发UI篇—懒加载
    2020121301-01
    2020120501-01
    2020113001-梦断代码-3
    2020112801-01
    2020112401
    2020112201-1
  • 原文地址:https://www.cnblogs.com/hznumqf/p/12325277.html
Copyright © 2011-2022 走看看