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


antiprimes: procedure options(main);
 
    /* count the factors of a number */
    countFactors: procedure(n) returns(fixed);
        declare (n, i, count) fixed;
        if n<2 then return(1);
        count = 1;
        do i=1 to n/2;
            if mod(n,i) = 0 then count = count + 1;
        end;
        return(count);
    end countFactors;
 
    declare maxFactors fixed static init (0);
    declare seen fixed static init (0);
    declare n fixed;
    declare factors fixed;
 
    do n=1 repeat(n+1) while(seen < 20);
        factors = countFactors(n);
        if factors > maxFactors then do;
            put edit(n) (F(5));
            maxFactors = factors;
            seen = seen + 1;
            if mod(seen,15) = 0 then put skip;
        end;
    end;
end antiprimes;