How to resolve the algorithm Product of min and max prime factors step by step in the ALGOL 68 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Product of min and max prime factors step by step in the ALGOL 68 programming language

Table of Contents

Problem Statement

Exactly as the task title implies.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Product of min and max prime factors step by step in the ALGOL 68 programming language

Source code in the algol programming language

BEGIN # find the product of the min and max prime factors of some numbers #
    INT max number = 100; # maximum number we will consider               #
    # sieve the primes to max number                                      #
    [ 0 : max number ]BOOL prime;
    prime[ 0 ] := prime[ 1 ] := FALSE;
    prime[ 2 ] := TRUE;
    FOR i FROM 3 BY 2 TO UPB prime DO prime[ i ] := TRUE  OD;
    FOR i FROM 4 BY 2 TO UPB prime DO prime[ i ] := FALSE OD;
    FOR i FROM 3 BY 2 TO ENTIER sqrt( UPB prime ) DO
        IF prime[ i ] THEN
            FOR s FROM i * i BY i + i TO UPB prime DO prime[ s ] := FALSE OD
        FI
    OD;
    # construct tables of the minimum and maximum prime factors of        #
    # numbers up to max number                                            #
    [ 1 : max number ]INT min pf; FOR i TO UPB min pf DO min pf[ i ] := 0 OD;
    [ 1 : max number ]INT max pf; FOR i TO UPB min pf DO max pf[ i ] := 0 OD;
    min pf[ 1 ] := 1;
    max pf[ 1 ] := 1;
    FOR i TO max number DO
        IF prime[ i ] THEN
            FOR j FROM i BY i TO UPB min pf DO
                IF min pf[ j ] = 0 THEN min pf[ j ] := i FI;
                max pf[ j ] := i
            OD
        FI
    OD;
    # print the products of the min and max prime factors                 #
    FOR i TO max number DO
        print( ( whole( min pf[ i ] * max pf[ i ], -5 ) ) );
        IF i MOD 10 = 0 THEN print( ( newline ) ) FI
    OD
END

  

You may also check:How to resolve the algorithm Maze solving step by step in the Racket programming language
You may also check:How to resolve the algorithm Euler method step by step in the Tcl programming language
You may also check:How to resolve the algorithm Kaprekar numbers step by step in the Liberty BASIC programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the Lisaac programming language
You may also check:How to resolve the algorithm Fibonacci n-step number sequences step by step in the 360 Assembly programming language