一本通 1616:A 的 B 次方

A 的 B 次方

快速幂板子题


Code:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
//Mystery_Sky
//
#define M 1000100
#define ll long long
ll a, b, m;

ll quickPow(ll x, ll k)
{
	ll ret = 1;
	while(k) {
		if(k & 1) ret = (ret * x) % m;
		k >>= 1;
		x = (x * x) % m;
	}
	return ret;
}

int main() {
	scanf("%lld%lld%lld", &a, &b, &m);
	printf("%lld
", quickPow(a, b));
	return 0;
}
原文地址:https://www.cnblogs.com/Benjamin-cpp/p/11122845.html