How to resolve the algorithm Anti-primes step by step in the Modula-2 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Anti-primes step by step in the Modula-2 programming language
Table of Contents
Problem Statement
The anti-primes (or highly composite numbers, sequence A002182 in the OEIS) are the natural numbers with more factors than any smaller than itself.
Generate and show here, the first twenty anti-primes.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Anti-primes step by step in the Modula-2 programming language
Source code in the modula-2 programming language
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.
You may also check:How to resolve the algorithm Check output device is a terminal step by step in the Racket programming language
You may also check:How to resolve the algorithm Sequence of primes by trial division step by step in the ARM Assembly programming language
You may also check:How to resolve the algorithm Playing cards step by step in the C programming language
You may also check:How to resolve the algorithm Jacobi symbol step by step in the Haskell programming language
You may also check:How to resolve the algorithm Parallel calculations step by step in the Phix programming language