问题描述:
求 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);
}
}
授权协议:创作共用 署名-非商业性使用 2.5 中国大陆
除注明外,本站文章均为原创;转载时请保留上述链接。