#define M 10003
int PowMod(int n, int p)
{
if (p == 1)
{
return n % M;
}
int temp = Pow(n, p/2);
int result = (temp*temp) % M;
if (p % 2 == 1)
{
result = (result*n) % M;
}
return result;
}
非递归:
#define M 10003
int PowMod(int n, int p)
{
int result = 1;
while (p > 0)
{
if (p % 2 == 1)
{
result = (result*n) % M;
}
p /= 2;
n = (n*n) % M;
}
return result;
}