快速幂模板

#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;
}

 

posted @ 2020-03-05 16:04  蒟蒻也有大梦想  阅读(87)  评论(0)    收藏  举报