Inconsummate numbers in base 10: Difference between revisions
→{{header|Free Pascal}}: Faster version checking Digitalsum, testing for max used factor.
m (→{{header|Wren}}: Changes to preamble and made second version more compact.) |
(→{{header|Free Pascal}}: Faster version checking Digitalsum, testing for max used factor.) |
||
Line 220:
=={{header|Pascal}}==
==={{header|Free Pascal}}===
<syntaxhighlight lang=pascal>
program Inconsummate;
{$IFDEF FPC}
{$MODE DELPHI}{$OPTIMIZATION ON,ALL}{$CODEALIGN proc=8,loop=1}
{$ENDIF}
uses
const
base = 10;
DgtSumLmt = base*base*base*base*base;
type
var
DgtSUm : tDgtSum;
max: Uint64;
procedure Init(var ds:tDgtSum);
var
i,l,k0,k1: NativeUint;
Begin
For i := 0 to base-1 do
ds[i] := i;
k0 := base;
repeat
k1 := k0-1;
For i := 1 to base-1 do
For l := 0 to k1 do
begin
ds[k0] := ds[l]+i;
inc(k0);
end;
until k0 >= High(ds);
end;
function GetSumOfDecDigits(n:Uint64):NativeUint;
var
r,d: NativeUint;
begin
result := 0;
repeat
r := n DIv DgtSumLmt;
d := n-r* DgtSumLmt;
result +=DgtSUm[d];
n := r;
until r = 0;
end;
i,d
begin
result
d := n;
For i := 1 TO 121 DO
begin
IF GetSumOfDecDigits(n)= i then
max := i;
Exit(false);
end;
n +=d;
end;
end;
var
d,
begin
Init(DgtSUm);
cnt := 0;
For d := 1 to 527 do//5375540350 do
begin
if
begin
if
end;
end;
writeln;
writeln('Count Number(count) Maxfactor needed');
max := 0;
lmt := 10;
For d := 1 to 50332353 do // 5260629551 do
begin
if OneTest(d) then
begin
if cnt =
begin
end;
end;
writeln(cnt);
end.
</syntaxhighlight>
{{out|@TIO.RUN}}
<pre>
62 63 65 75 84 95 161 173 195 216
261 266 272 276 326 371 372 377 381 383
386 387 395 411 416 422 426 431 432 438
Line 379 ⟶ 328:
491 492 493 494 497 498 516 521 522 527
Count Number(count) Maxfactor needed
10000 59853 54
100000 536081 63
1000000 5073249 69
10000000 50332353 81
10000000
Real time: 23.898 s
@Home AMD 5600G 4.4 Ghz:
Count Number(count) Maxfactor needed
10 216 27
100 936 36
1000 6996 36
10000 59853 54
100000 536081 63
1000000 5073249 69
10000000 50332353 81 //real 0m6,395s
100000000 517554035 87
1000000000 5260629551 96
1000000000
real 15m54,915s
</pre>
|