Legolas-ի խոսքերից
բա տենց ասա
Կոդ:
int PolyFactorial(int n)
{
if(n<1)
return -1;
int res=1;
int k=n%2;
while(k<n)
{
k+=2;
res*=k;
}
return res;
}
Ավելի ճիշտ է այսպես.
Կոդ:
unsigned int HalfFactorial(unsigned int n)
{
unsigned int ret = 1;
while(n>1)
{
ret *= n;
n -= 2;
}
return ret;
}
Քո գրածով կոմպիլյատորը գեներացնում է հետևյալ կոդը
Կոդ:
mov ecx, edx
and ecx, -2147483647
mov eax, 1
jns SHORT $LN13@PolyFactor
dec ecx
or ecx, -2
inc ecx
$LN13@PolyFactor:
cmp ecx, edx
jge SHORT $LN1@PolyFactor
push esi
npad 7
$LL2@PolyFactor:
add ecx, 2
mov esi, ecx
imul eax, esi
cmp ecx, edx
jl SHORT $LL2@PolyFactor
pop esi
$LN1@PolyFactor:
ret 0
Իսկ իմ գրածով
Կոդ:
mov ecx, 100
mov eax, 1
npad 6
$LL2@HalfFactor:
imul eax, ecx
sub ecx, 2
cmp ecx, 1
ja SHORT $LL2@HalfFactor
ret 0
Էջանիշներ