Anonymous user
Humble numbers: Difference between revisions
m
→{{header|Pascal}}: checked values with different float types
m (→{{header|Pascal}}: improvement check up to 1000 digits) |
m (→{{header|Pascal}}: checked values with different float types) |
||
Line 748:
=={{header|Pascal}}==
modification of hamming-numbers http://rosettacode.org/wiki/Hamming_numbers#a_fast_alternative
<BR>Using float80/extended and float64/double and single/float32 version, to get a possibility to check values.
float80 and float64 got same values up to 877.float64 is 2,3x faster than float80<BR>
float32 get wrong at 37 digits,->37 104925 instead of 104926<BR>
<lang pascal>program hammNumb;▼
runtime: 2 x digits => ~ runtime 2^4 <BR>
{$IFDEF FPC}
{$MODE DELPHI}
{$OPTIMIZATION ON,ALL}
{$CODEALIGN proc=
{$ALIGN 16}
{$ELSE}
Line 765 ⟶ 767:
const
//PlInit(4); <= maxPrimFakCnt+1
maxPrimFakCnt = 3;//
minElemCnt = 10;
type
tPrimList = array of NativeUint;
tnumber =
tpNumber= ^tnumber;
tElem = record
n : tnumber;//ln(prime[0]^Pots[0]*...
Pots: array[0..maxPrimFakCnt] of word;
end;
Line 892 ⟶ 893:
end;
function LoEGetActElem(pFr:tpFaktorRec):tElem;inline;
Begin
with pFr^ do
Line 898 ⟶ 899:
end;
function LoEGetActLstNumber(pFr:tpFaktorRec):tpNumber;inline;
Begin
with pFr^ do
Line 938 ⟶ 939:
Begin
frInsElems[cnt] := LoEGetNextElement(frNextFr);
inc(cnt);
IF cnt > High(frInsElems) then
Line 963 ⟶ 962:
frMaxIdx:= u;
repeat
IF pElems^[i].n < frInsElems[cnt].n then
Begin
Line 1,012 ⟶ 1,010:
var
pElems : tpElemArr;
j,PotNum :
lnPrime : tnumber;
begin
with pFR^ do
Begin
//increase all Elements by factor
pElems := @frElems[0];
LnPrime := frLnPrime;
PotNum := frPotNo;
for j := frMaxIdx Downto 0 do
with pElems^[j] do
Begin
n :=
inc(Pots[
end;
//x^j -> x^(j+1)
Line 1,028 ⟶ 1,029:
with frActNumb do
begin
n:= j*
Pots[
end;
frActPot := j;
Line 1,099 ⟶ 1,100:
procedure GetDigitCounts(MaxDigit:Uint32);
var
FA: tArrFR;▼
T1,T0 : TDateTime;
▲ FA: tArrFR;
i,j,LastCnt : NativeUint;
Begin
Line 1,114:
repeat
inc(j);
IF (Pots[2]= i) AND (Pots[0]= i) then
break;
until false;
writeln(i:4,j-LastCnt:
LastCnt := j;
inc(i);
Line 1,136 ⟶ 1,135:
End.</lang>
{{out}}
<pre>1 2 3 4 5 6 7 8 9 10 12 14 15 16 18 20 21 24 25 27 28 30 32 35 36 40 42 45 48 49 50 54 56 60 63 64 70 72 75 80 81 84 90 96 98 100 105 108 112 120
Digits count total count
1 9 9 0.000 s
2 36 45 0.000 s
3 95 140 0.000 s
4 197 337 0.000 s
5 356 693 0.
6 579 1272 0.
7 882 2154 0.
8 1272 3426 0.
9 1767 5193 0.
10 2381 7574 0.
11 3113 10687 0.
12 3984 14671 0.
13 5002 19673 0.
14 6187 25860 0.
15 7545 33405 0.
16 9081 42486 0.
17 10815 53301 0.
18 12759 66060 0.
19 14927 80987 0.
20 17323 98310 0.
21 19960 118270 0.
22 22853 141123 0.
23 26015 167138 0.
24 29458 196596 0.
25 33188 229784 0.
26 37222 267006 0.
27 41568 308574 0.
28 46245 354819 0.
29 51254 406073 0.
30 56618 462691 0.
31 62338 525029 0.
32 68437 593466 0.
33 74917 668383 0.
34 81793 750176 0.
35 89083 839259 0.
36 96786 936045 0.
37 104926 1040971 0.
38 113511 1154482 0.
39 122546 1277028 0.
40 132054 1409082 0.
41 142038 1551120 0.
42 152515 1703635 0.
43 163497 1867132 0.
44 174986 2042118 0.
45 187004 2229122 0.
46 199565 2428687 0.
47 212675 2641362 0.
48 226346 2867708 0.
49 240590 3108298 0.
50 255415 3363713 0.
51 270843 3634556 0.
52 286880 3921436 0.
53 303533 4224969 0.
54 320821 4545790 0.
55 338750 4884540 0.
56 357343 5241883 0.
57 376599 5618482 0.
58 396533 6015015 0.
59 417160 6432175 0.
60 438492 6870667 0.
61 460533 7331200 0.
62 483307 7814507 0.
63 506820 8321327 0.
64 531076 8852403 0.
65 556104 9408507 0.
66 581902 9990409 0.
67 608483 10598892 0.
68 635864 11234756 0.
69 664053 11898809 0.
70 693065 12591874 0.
71 722911 13314785 0.
72 753593 14068378 0.
73 785141 14853519 0.
74 817554 15671073 0.
75 850847 16521920 0.
76 885037 17406957 0.
77 920120 18327077 0.
78 956120 19283197 0.
79 993058 20276255 0.
80 1030928 21307183 0.
81 1069748 22376931 0.
82 1109528 23486459 0.
83 1150287 24636746 0.
84 1192035 25828781 0.
85 1234774 27063555 0.
86 1278527 28342082 0.
87 1323301 29665383 0.
88 1369106 31034489 0.
89 1415956 32450445 0.
90 1463862 33914307 0.
91 1512840 35427147 0.
92 1562897 36990044 0.
93 1614050 38604094 0.
94 1666302 40270396 0.
95 1719669 41990065 0.
96 1774166 43764231 0.
97 1829805 45594036 0.
98 1886590 47480626 0.
99 1944540 49425166 0.
100 2003661 51428827 0.
102 2125486 55618285 0.948 s
103 2188204 57806489 0.991 s
104 2252146 60058635 1.026 s
105 2317319 62375954 1.062 s
106 2383733 64759687 1.110 s
107 2451413 67211100 1.147 s
108 2520360 69731460 1.186 s
109 2590584 72322044 1.237 s
110 2662102 74984146 1.278 s
.. shortened
120 3450981 105831533 1.795 s
130 4382079 145340170 2.450 s
140 5467187 194997130 3.298 s
150 6718091 256407329 4.318 s
170 9764417 421496245 7.055 s
190 13615367 655803459 10.972 s
200 15872045 804178604 13.424 s
600 425728730 64142692268 1039.928 s
..
876 1323548095 290737888948 4690.230 s
877 1328082553 292065971501 4709.931 s
</pre>
▲ 100 2003661 51428827 0.319 s
▲ 200 15872045 804178604 5.428 s
▲ 300 53391941 4039954757 27.791 s
▲ 400 126350163 12719142480 87.721 s
▲ 500 246533493 30980806733 214.313 s
▲ 700 675722681 118701223590 821.831 s
▲ 800 1008302151 202331504969 1402.278 s
=={{header|Perl}}==
|