29 lines
648 B
Plaintext
29 lines
648 B
Plaintext
function integer Lagarias (N); \Lagarias arithmetic derivative
|
|
integer N;
|
|
integer F, Q;
|
|
|
|
function integer SmallPF (J, K); \Smallest prime factor
|
|
integer J, K;
|
|
return if rem(J/K) = 0 then K else SmallPF(J, K+1);
|
|
|
|
begin
|
|
if N < 0
|
|
then return -Lagarias (-N)
|
|
else if N = 0 or N = 1
|
|
then return 0
|
|
else begin
|
|
F := SmallPF (N, 2); Q := N / F;
|
|
return if Q = 1
|
|
then 1
|
|
else Q * Lagarias (F) + F * Lagarias (Q)
|
|
end;
|
|
end \Lagarias\ ;
|
|
|
|
integer N;
|
|
begin
|
|
for N:= -99 to 100 do begin
|
|
IntOut(0, Lagarias(N) );
|
|
if rem(N/10) = 0 then CrLf(0) else ChOut(0, 9\tab\);
|
|
end;
|
|
end
|