Deceptive numbers: Difference between revisions

m
→‎{{header|Free Pascal}}: only checking odd divisors halving timing
(→‎{{header|Perl}}: prepend pascal)
m (→‎{{header|Free Pascal}}: only checking odd divisors halving timing)
Line 114:
=={{header|Pascal}}==
==={{header|Free Pascal}}===
Brute force, not using gmp. Runtime ~ n^2. <BR>
Like Wren,et alias only checking odd divisors.
<lang pascal>
<lang pascal>program DeceptiveNumbers;
{$IfDef FPC} {$Optimization ON,ALL} {$ENDIF}
{$IFDEF FPC}
{$IfDef Windows} {$APPTYPE CONSOLE} {$ENDIF}
{$OPTIMIZATION ON,ALL}
{$ENDIF}
{$IFDEF WINDOWS}
{$APPTYPE CONSOLE}
{$ENDIF}
uses
sysutils;
const
LIMIT = 100000;//1E6 takes over 5 min on Ryzen 2200G
RepInitLen = 13; //Uint64 19 decimal digits -> max 6 digits divisor
DecimalDigits = 10*1000*1000*1000*1000;//1E13
Line 136 ⟶ 132:
K: tmyUint64;
MaxKIdx : Int32;
 
procedure OutK(const K:tmyUint64);
var
i : Uint32;
begin
For i := MaxKidx downto 0 do
begin
write(k[i]:13);
end;
writeln;
end;
 
function isPrime(n: UInt64):boolean;
Line 195 ⟶ 202:
 
var
i,j,cnt : UInt64;
BEGIN
fillchar(K,SizeOF(K),#0);
MaxKIdx:= 0;
cnt := 0;
For i := 7 to LIMIT do5;
For j := 3 to (LIMIT-1) DIV 2 do
begin
inc(i,2);
if isprime(i) OR (i mod 3=0) then
continue;
Line 212 ⟶ 221:
end;
end;
{$IFDEFIfDef WINDOWSWindows}
readln;
{$ENDIF}
END.</lang>
</lang pascal>
{{out|@TIO.RUN}}
<pre>
Real time: 21.883338 s User time: 21.841293 s Sys. time: 0.030037 s CPU share: 99.5842 %
91, 259, 451, 481, 703, 1729, 2821, 2981, 3367, 4141,
4187, 5461, 6533, 6541, 6601, 7471, 7777, 8149, 8401, 8911,
Line 227 ⟶ 237:
97273, 97681,
</pre>
 
=={{header|Perl}}==
<lang perl>use strict;
Anonymous user