我当前用于计算 Legendre 符号的代码是
inline int legendre(int pa, int pm){
register unsigned int a = pa;
register unsigned int m = pm;
int t = 1;
int tmp=0;
while (a>1) {
tmp=__builtin_ctz(a);//a=x*2^tmp, where x is odd
a>>=tmp;
if(tmp&1 &&((m&7)==3 || (m&7)==5))//if it is an odd power and m=3,5 mod 8
t=-t;//invert result
if((a&3)==3 && (m&3)==3)//if m=3 mod 4 and a=3 mod 4
t=-t;//invert result
m %= a;
tmp=a;
a=m;
m=tmp;//exchange variables
}
if (m == 1) return t;
return 0;
}
这里可以进行任何优化吗?