The anti-primes
(or highly composite numbers, sequence A002182 in the OEIS)
are the natural numbers with more factors than any smaller than itself.



Task

Generate and show here, the first twenty anti-primes.



Related tasks

   Factors of an integer
   Sieve of Eratosthenes


MODULE Antiprimes;
FROM InOut IMPORT WriteCard, WriteLn;
 
CONST Amount = 20;
VAR max, seen, n, f: CARDINAL;
 
PROCEDURE factors(n: CARDINAL): CARDINAL;
    VAR facs, div: CARDINAL;
BEGIN
    IF n<2 THEN RETURN 1; END;
    facs := 2;
    FOR div := 2 TO n DIV 2 DO
        IF n MOD div = 0 THEN
            INC(facs);
        END;
    END;
    RETURN facs;
END factors;
 
BEGIN
    max := 0;
    seen := 0;
    n := 1;
    WHILE seen < Amount DO
        f := factors(n);
        IF f > max THEN
            WriteCard(n,5);
            max := f;
            INC(seen);
            IF seen MOD 10 = 0 THEN WriteLn(); END;
        END;
        INC(n);
    END;
END Antiprimes.