void power(unsigned int a,unsigned int p,unsigned int n,unsigned int &result,bool &composite)
{
unsigned int x;
if(p == 0)
{
result = 1;
}
else
{
power(a,p/2,n,x,composite); //递归计算
result = (x*x)%n; //二次探测
if((result == 1) && (x!=1) && (x!=n-1))
{
composite = true;
}
if((p%2)==1)
{
result = (result*a)%n;
}
}
}
{
unsigned int x;
if(p == 0)
{
result = 1;
}
else
{
power(a,p/2,n,x,composite); //递归计算
result = (x*x)%n; //二次探测
if((result == 1) && (x!=1) && (x!=n-1))
{
composite = true;
}
if((p%2)==1)
{
result = (result*a)%n;
}
}
}