Anonymous user
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.
Like Wren,et alias only checking odd divisors.
<lang pascal>▼
<lang pascal>program DeceptiveNumbers;
{$IfDef FPC} {$Optimization ON,ALL} {$ENDIF}
{$IfDef Windows} {$APPTYPE CONSOLE} {$ENDIF}▼
▲ {$APPTYPE CONSOLE}
uses
sysutils;
const
LIMIT = 100000;//1E6 takes over 5 min
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 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;
{$
{$ENDIF}
END.
{{out|@TIO.RUN}}
<pre>
Real time:
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;
|