Arithmetic numbers: Difference between revisions
Content deleted Content added
Arithmetic numbers in various BASIC dialents (True BASIC, XBasic and Yabasic) |
m →{{header|Free Pascal}}: up to 1 billion |
||
Line 603: | Line 603: | ||
</pre> |
</pre> |
||
==={{header|Free Pascal}}=== |
==={{header|Free Pascal}}=== |
||
using prime decomposition is lengthy, but much faster. |
using prime decomposition is lengthy, but much faster.<br> |
||
Change last lines of [[Factors_of_an_integer#using_Prime_decomposition]] even more. |
|||
<lang pascal> |
<lang pascal> |
||
program ArithmeticNumbers; |
program ArithmeticNumbers; |
||
Line 768: | Line 769: | ||
1000000 1228663 905043 |
1000000 1228663 905043 |
||
Real time: 0.678 s CPU share: 99.40 %</pre> |
Real time: 0.678 s CPU share: 99.40 %</pre> |
||
[[Factors_of_an_integer#using_Prime_decomposition]] added function and change main routine. |
|||
<lang pascal> |
|||
const |
|||
//make size of sieve using 11 MB of 16MB Level III cache |
|||
SizePrDeFe = 192*1024; |
|||
..... |
|||
function IsArithmetic(const PrimeFact:tPrimeFac):boolean;inline; |
|||
begin |
|||
with PrimeFact do |
|||
IsArithmetic := pfSumOfDivs mod pfDivCnt = 0; |
|||
end; |
|||
var |
|||
pPrimeDecomp :tpPrimeFac; |
|||
T0:Int64; |
|||
n,lmt,cnt,primeCnt : NativeUInt; |
|||
Begin |
|||
InitSmallPrimes; |
|||
T0 := GetTickCount64; |
|||
cnt := 1; |
|||
primeCnt := 1; |
|||
lmt := 10; |
|||
n := 2; |
|||
Init_Sieve(n); |
|||
repeat |
|||
pPrimeDecomp:= GetNextPrimeDecomp; |
|||
if IsArithmetic(pPrimeDecomp^) then |
|||
begin |
|||
inc(cnt); |
|||
if pPrimeDecomp^.pfDivCnt = 2 then |
|||
inc(primeCnt); |
|||
end; |
|||
if cnt = lmt then |
|||
begin |
|||
writeln(lmt:14,n:14,lmt-primeCnt:14); |
|||
lmt := lmt*10; |
|||
end; |
|||
inc(n); |
|||
until lmt>1000*1000*1000; |
|||
T0 := GetTickCount64-T0; |
|||
writeln; |
|||
end.</lang> |
|||
{{out|@Home AMD 5600G}} |
|||
<pre> |
|||
10 17 3 |
|||
100 149 65 |
|||
1000 1361 782 |
|||
10000 12953 8458 |
|||
100000 125587 88219 |
|||
1000000 1228663 905043 |
|||
10000000 12088243 9206547 |
|||
100000000 119360473 93192812 |
|||
1000000000 1181451167 940432725 |
|||
20.78user 0.00 system 0:20.79 elapsed 99%CPU </pre> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |