问题描述:
求 B ^ P % M = ?
代码实现:
#include using namespace std; int main() { freopen("input.txt","r",stdin); int B,P,M; while (~scanf("%d%d%d",&B,&P,&M)) { int ans = 1; B = B % M; while (P > 0) { if (P%2) ans = ans * B % M; P /= 2; B = (B*B) % M; } printf("%dn",ans); } }