zoukankan      html  css  js  c++  java
  • [洛谷P5091]【模板】欧拉定理

    题目大意:求$a^bmod m(aleqslant10^9,mleqslant10^6,bleqslant10^{2 imes10^7})$

    题解:扩展欧拉定理:
    $$
    a^bequiv
    egin{cases}
    a^{bmod{varphi(p)}} &(a,b)=1\
    a^b &(a,b) ot=1,b<varphi(p)\
    a^{bmod{varphi(p)}+varphi(p)} &(a,p) ot=1,bgeqslantvarphi(p)
    end{cases}
    pmod{p}
    $$
    可以求出$varphi(m)$,然后快速幂即可

    卡点:

    C++ Code:

    #include <cstdio>
    #include <cmath>
    #include <cctype>
    int a, mod, phi, b;
    namespace Math {
    	int Phi(int n) {
    		int t = std::sqrt(n), res = n;
    		for (int i = 2; i <= t; i++) if (n % i == 0) {
    			res = res / i * (i - 1);
    			while (n % i == 0) n /= i;
    		}
    		if (n > 1) res = res / n * (n - 1);
    		return res;
    	}
    	inline int pw(int base, int p) {
    		int res = 1;
    		for (; p; p >>= 1, base = static_cast<long long> (base) * base % mod) if (p & 1) res = static_cast<long long> (res) * base % mod;
    		return res;
    	}
    }
    
    int read() {
    	int ch, x, c = 0;
    	while (isspace(ch = getchar()));
    	for (x = ch & 15; isdigit(ch = getchar()); ) {
    		x = x * 10 + (ch & 15);
    		if (x >= phi) x %= phi, c = phi;
    	}
    	return x + c;
    }
    int main() {
    	scanf("%d%d", &a, &mod);
    	phi = Math::Phi(mod);
    	b = read();
    	printf("%d
    ", Math::pw(a, b));
    	return 0;
    }
    

      

  • 相关阅读:
    zombodb 数据类型映射
    Amundsen — Lyft’s data discovery & metadata engine
    The Twelve-Factor Container
    zombodb sql functions 说明
    zombodb 得分以及高光
    windows openssh 设置root 目录
    zombodb 聚合函数
    zombodb 索引管理
    zombodb 索引创建
    zombodb 低级api 操作
  • 原文地址:https://www.cnblogs.com/Memory-of-winter/p/10114044.html
Copyright © 2011-2022 走看看