Anti-primes: Difference between revisions

Content deleted Content added
New draft task with python example.
 
{{header|Pascal}} added pascal
Line 7:
;Task:
Generate and show here, the first twenty anti-primes.
 
 
;Related task:
::*   [[Factors of an integer]]
 
=={{header|Pascal}}==
Easy factoring without primes.Decided to show count of factors.
<lang pascal>program AntiPrimes;
{$IFdef FPC}
{$MOde Delphi}
{$IFEND}
function getFactorCnt(n:NativeUint):NativeUint;
var
divi,quot,pot,lmt : NativeUint;
begin
result := 1;
divi := 1;
lmt := trunc(sqrt(n));
while divi < n do
Begin
inc(divi);
pot := 0;
repeat
quot := n div divi;
if n <> quot*divi then
BREAK;
n := quot;
inc(pot);
until false;
result := result*(1+pot);
//IF n= prime leave now
if divi > lmt then
BREAK;
end;
end;
 
var
i,Count,FacCnt,lastCnt: NativeUint;
begin
count := 0;
lastCnt := 0;
i := 1;
repeat
FacCnt := getFactorCnt(i);
if lastCnt < FacCnt then
Begin
write(i,'(',FacCnt,'),');
lastCnt:= FacCnt;
inc(Count);
if count = 12 then
Writeln;
end;
inc(i);
until Count >= 20;
writeln;
end.</lang>;Output:<pre>1(1),2(2),4(3),6(4),12(6),24(8),36(9),48(10),60(12),120(16),180(18),240(20),
360(24),720(30),840(32),1260(36),1680(40),2520(48),5040(60),7560(64)</pre>
=={{header|Python}}==
Uses the fast prime function from [[Factors of an integer#Python]]