1046 A^B Mod C

1046 A^B Mod C

快速幂取模

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int qmi(int a,int b,int c) {
    int res = 1 % c;// 防止 c == 1,b == 0
    while(b) {
        if(b & 1) res = (LL)res * a % c;
        a = (LL)a * a % c;
        b >>= 1;
    }
    return res;
}
int main() {
    int a,b,c;
    cin >> a >> b >> c;
    cout << qmi(a,b,c);
    return 0;
}
posted @ 2020-03-12 14:53  lukelmouse  阅读(100)  评论(0编辑  收藏  举报