• 【模板】欧拉定理


    题目背景

    模板题,无背景

    题目描述

    给你三个正整数,a,m,ba,m,ba,m,b,你需要求:
    abmodma^b mod mabmodm

    输入输出格式

    输入格式:

    一行三个整数,a,m,ba,m,ba,m,b

    输出格式:

    一个整数表示答案

    输入输出样例

    输入样例#1: 复制
    2 7 4
    输出样例#1: 复制
    2
    输入样例#2: 复制
    998244353 12345 98765472103312450233333333333
    输出样例#2: 复制
    5333

    说明

    注意输入格式,a,m,ba,m,ba,m,b 依次代表的是底数、模数和次数

    样例1解释:
    24mod7=22^4 mod 7 = 224mod7=2
    输出2

    数据范围:
    对于全部数据:
    1≤a≤1091≤a≤10^91a109
    1≤b≤10200000001≤b≤10^{20000000}1b1020000000
    1≤m≤1061≤m≤10^61m106

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstdlib>
    #include<cstring>
    #include<string>
    #include<cmath>
    #include<map>
    #include<set>
    #include<vector>
    #include<queue>
    #include<bitset>
    #include<ctime>
    #include<time.h>
    #include<deque>
    #include<stack>
    #include<functional>
    #include<sstream>
    //#include<cctype>
    //#pragma GCC optimize(2)
    using namespace std;
    #define maxn 200005
    #define inf 0x7fffffff
    //#define INF 1e18
    #define rdint(x) scanf("%d",&x)
    #define rdllt(x) scanf("%lld",&x)
    #define rdult(x) scanf("%lu",&x)
    #define rdlf(x) scanf("%lf",&x)
    #define rdstr(x) scanf("%s",x)
    #define mclr(x,a) memset((x),a,sizeof(x))
    typedef long long  ll;
    typedef unsigned long long ull;
    typedef unsigned int U;
    #define ms(x) memset((x),0,sizeof(x))
    const long long int mod = 98765431;
    #define Mod 1000000000
    #define sq(x) (x)*(x)
    #define eps 1e-5
    typedef pair<int, int> pii;
    #define pi acos(-1.0)
    //const int N = 1005;
    #define REP(i,n) for(int i=0;i<(n);i++)
    typedef pair<int, int> pii;
    
    inline int rd() {
    	int x = 0;
    	char c = getchar();
    	bool f = false;
    	while (!isdigit(c)) {
    		if (c == '-') f = true;
    		c = getchar();
    	}
    	while (isdigit(c)) {
    		x = (x << 1) + (x << 3) + (c ^ 48);
    		c = getchar();
    	}
    	return f ? -x : x;
    }
    
    
    ll gcd(ll a, ll b) {
    	return b == 0 ? a : gcd(b, a%b);
    }
    int sqr(int x) { return x * x; }
    
    
    
    /*ll ans;
    ll exgcd(ll a, ll b, ll &x, ll &y) {
    	if (!b) {
    		x = 1; y = 0; return a;
    	}
    	ans = exgcd(b, a%b, x, y);
    	ll t = x; x = y; y = t - a / b * y;
    	return ans;
    }
    */
    
    int a, m, phi = 1;
    int B, fg;
    ll qpow(ll x, ll y) {
    	ll ans = 1;
    	while (y) {
    		if (y % 2)ans = ans * x%m;
    		x = x * x%m; y >>= 1;
    	}
    	return ans;
    }
    
    int main()
    {
    	//	ios::sync_with_stdio(0);
    	rdint(a); rdint(m);
    	a %= m; int tmp = m;
    	for (int i = 2; i <= sqrt(tmp); i++) {
    		if (tmp%i)continue;
    		phi *= (i - 1); tmp /= i;
    		while (tmp%i == 0) {
    			phi *= i; tmp /= i;
    		}
    	}
    	if (tmp > 1)phi *= (tmp - 1);
    	char ch;
    	while ((ch = getchar()) < '0' || ch > '9');
    	while (B = B * 10ll + (ch^'0'), (ch = getchar()) >= '0'&&ch <= '9') {
    		if (B >= phi)fg = 1, B %= phi;
    	}
    	if (B >= phi)fg = 1, B %= phi;
    	if (fg)B += phi;
    	printf("%lld
    ", qpow(a * 1ll, B * 1ll));
    	return 0;
    }
    
  • 相关阅读:
    Vuejs的一些总结
    vue.js中$emit的理解
    Vue.js——60分钟快速入门
    [ARC096E] Everything on It
    [ARC093E] Bichrome Spanning Tree
    [ARC093F] Dark Horse
    [ARC100F] Colorful Sequences
    卡特兰数 学习笔记
    【原】图练习
    【原】图
  • 原文地址:https://www.cnblogs.com/zxyqzy/p/10372861.html
Copyright © 2020-2023  润新知