How to resolve the algorithm Anti-primes step by step in the Oberon-2 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Anti-primes step by step in the Oberon-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 Oberon-2 programming language

Source code in the oberon-2 programming language

MODULE AntiPrimes;

  IMPORT Out;
    
  CONST
    Amount = 20;
    
  VAR
    Max,Seen,N,F:INTEGER;

  PROCEDURE Factors(N:INTEGER):INTEGER;
    VAR
      Facts,Div:INTEGER;
  BEGIN
    IF N < 2 THEN RETURN 1 END;
    Facts := 2;
    FOR Div := 2 TO N DIV 2 DO
      IF N MOD Div = 0 THEN INC(Facts) END;
    END;
    RETURN Facts;
  END Factors;
  
BEGIN
  Max := 0;
  Seen := 0;
  N := 1;
  WHILE Seen < Amount DO
    F := Factors(N);
    IF F > Max THEN
      Out.Int(N,5);
      Max := F;
      INC(Seen);
      IF Seen MOD 10 = 0 THEN Out.Ln END;
    END;
    INC(N);
  END;
END AntiPrimes.

  

You may also check:How to resolve the algorithm Number names step by step in the Factor programming language
You may also check:How to resolve the algorithm Chinese remainder theorem step by step in the VBA programming language
You may also check:How to resolve the algorithm Sorting algorithms/Comb sort step by step in the Eiffel programming language
You may also check:How to resolve the algorithm JortSort step by step in the OCaml programming language
You may also check:How to resolve the algorithm Fork step by step in the Delphi programming language