Zumkeller numbers: Difference between revisions

m
→‎{{header|Pascal}}: one partition includes n
m (→‎{{header|Phix}}: added syntax colouring the hard way)
m (→‎{{header|Pascal}}: one partition includes n)
Line 2,700:
=={{header|Pascal}}==
modified [[practical numbers]] and [[Factors_of_an_integer#using_Prime_decomposition]]
Now using the trick, that one partition sum must include n.
<lang pascal>program zumkeller;
{$IFDEF FPC}
{$MODE DELPHI}{$OPTIMIZATION ON,ALL}{$COPERATORS ON}
{$ELSE}
{$APPTYPE CONSOLE}
Line 2,720 ⟶ 2,721:
 
tprimeFac = record
pfPrims : array[0..1315] of tPot;
pfSumOfDivs :Uint64;
pfCnt,
pfDivCnt,
pfNum,pfdummy : Uint32;
end;
 
Line 2,866 ⟶ 2,867:
Begin
i := DivCount(primeDecomp);
setlength(Divs,0);
setlength(Divs,i);
 
pDivs := @Divs[0];
pDivs[0] := 1;
Line 2,896 ⟶ 2,897:
 
var
Dummy : QWord;
HasSum: array of byte;
Divs:tDivisors;
Line 2,910 ⟶ 2,912:
hs0[0] := 1; //empty set
maxlimit := 0;
//Stopps at last by Divs[?] = n
for idx := 0 to High(Divs) do
begin
iif := Divshs0[idxmiddle]; <> 0 then
If i > middle thenEXIT(true);
BREAK;
IFi maxlimit >:= middle-iDivs[idx]; then
if maxLimit+i > middle then
Begin
maxlimit := middle-i;
hs1 := if @hs0[maxLimiti]; <> 0 then
EXIT(true)
end;
//next sum
hs1 := @hs0[i];
For j := maxlimit downto 0 do
hs1[j] := hs1[j] OR hs0[j];
Line 2,938 ⟶ 2,936:
sum := SumOfDiv(primeDecomp);
//sum must be even and n not deficient
if Odd(sum) ORor (sum < 2*nN) thenTHEN
EXIT(false);
// If Odd(n) then EXIT(Not(Odd(sum - 2*n)));
//Now one needs to get the divisors
 
GetDivs(primeDecomp,Divs);
//erase divisor = n, one partition includes n
sum := sum shr 1;
setlength(Divs,Length(DIVS)-1);
 
lesum := length(HasSum)sum shr 1 -n;
if le <:= sum+10; then
if le > length(HasSum) then
Begin
le := sum +1;
setlength(HasSum,0);
setlength(HasSum, le);
end
else
fillChar(HasSum[0],sumle,#0);
result := isZumKeller(Divs,sum);
 
result := isZumKeller(Divs,sum);
end;
 
Line 2,982 ⟶ 2,981:
T0 : Int64;
sol : array of Uint32;
n, col,limit,count: NativeInt;
begin
InitSmallPrimes;
setlength(HasSum,831);
setlength(sol,MAX+1);
 
T0 := GetTickCount64;
col := ColCnt;
count := 0;
Limit := MAX;
n := 12;//99500
writeln('The first ',MAX,' zumkeller numbers');
repeat
Line 3,003 ⟶ 3,001:
until count = Limit;
OutSol(sol,4,20,Limit);
writeln('The first odd 40 zumkeller numbers');
n := 1;
Line 3,015 ⟶ 3,014:
inc(n,2);
until count = Limit;
OutSol(sol,86,10,Limit);
 
n := 1;
Line 3,031 ⟶ 3,030:
inc(n,2);
until count = Limit;
OutSol(sol,8,108,Limit);
 
T0 := GetTickCount64-T0;
writeln('runtime ',T0/1000:0:3,' s');
 
setlength(HasSum, 0);
{$IFNDEF UNIX} readln; {$ENDIF}
end.</lang>
 
</lang>
{{out}}
<pre>TIO.RUN
Line 3,067 ⟶ 3,065:
1095633 1108107 1145529 1162161 1198197 1224531 1270269 1307691 1324323 1378377
 
runtime 0.441371 s
 
Real time: 0.579 s User time: 0.533 s Sys. time: 0.042 s CPU share: 99.41 %
</pre>
 
Anonymous user