Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
40
Task/Prime-decomposition/XPL0/prime-decomposition.xpl0
Normal file
40
Task/Prime-decomposition/XPL0/prime-decomposition.xpl0
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
\ Prime decomposition
|
||||
code Abs=0, Rem=2, CrLf=9, IntIn=10, IntOut=11, Text=12;
|
||||
define MaxFacIndex = 30;
|
||||
\ -(2^31) has most prime factors (31 twos) than other 32-bit signed integer.
|
||||
integer I, N, Facs(MaxFacIndex), FacsCnt;
|
||||
|
||||
procedure CalcFacs(N, Facs, FacsCnt);
|
||||
integer N, Facs, FacsCnt;
|
||||
integer I, Cnt;
|
||||
begin
|
||||
N:= Abs(N);
|
||||
Cnt:=0;
|
||||
if N >= 2 then
|
||||
begin
|
||||
I:= 2;
|
||||
while I * I <= N do
|
||||
begin
|
||||
if Rem(N / I) = 0 then
|
||||
begin
|
||||
N:= N / I;
|
||||
Facs(Cnt):= I; Cnt:= Cnt + 1;
|
||||
I:= 2
|
||||
end
|
||||
else
|
||||
I:= I + 1
|
||||
end;
|
||||
Facs(Cnt):= N; Cnt:= Cnt + 1
|
||||
end;
|
||||
FacsCnt(0):= Cnt
|
||||
end;
|
||||
|
||||
begin
|
||||
Text(0, "Enter a number: "); N:= IntIn(0);
|
||||
CalcFacs(N, Facs, addr FacsCnt);
|
||||
for I:= 0 to FacsCnt - 2 do
|
||||
begin
|
||||
IntOut(0, Facs(I)); Text(0, " ")
|
||||
end;
|
||||
IntOut(0, Facs(FacsCnt - 1)); CrLf(0)
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue