快速幂模板
#include <bits/stdc++.h> using namespace std; typedef long long LL; inline LL quickpow (LL x , LL y , LL mod){ LL ans = 1;//自定义函数可作为快速幂模型 for ( ; y ; x = x * x % mod , y >>= 1) y & 1 ? ans = ans * x % mod : 0; return (LL) ans % mod ; } signed main() { LL b,k,p; cin >> b >> k >> p ; cout << b << '^' << k << " mod " << p << '=' << quickpow(b , k , p) << endl ; return 0; }

浙公网安备 33010602011771号