How to resolve the algorithm Product of min and max prime factors step by step in the Draco 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 Draco 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 Draco programming language

Source code in the draco programming language

proc sieve([*]bool prime) void:
    word p, c, max;
    max := dim(prime,1)-1;

    prime[0] := false;      
    prime[1] := false;    
    for p from 2 upto max do prime[p] := true od;
    for p from 2 upto max/2 do
        for c from p*2 by p upto max do
            prime[c] := false
        od
    od
corp

proc lo_fac([*]bool prime; word n) word:
    word i;
    if n=1 then 1
    else 
        i := 2;
        while i<=n and not (prime[i] and n%i=0) do i := i + 1 od;
        i
    fi
corp

proc hi_fac([*]bool prime; word n) word:
    word i;
    if n=1 then 1
    else
        i := n;
        while i>=2 and not (prime[i] and n%i=0) do i := i - 1 od;
        i
    fi
corp

proc main() void:
    word i, MAX = 100;
    [MAX+1]bool prime;
    sieve(prime);
    
    for i from 1 upto MAX do
        write(lo_fac(prime, i) * hi_fac(prime, i):6);
        if i%10 = 0 then writeln() fi
    od
corp

  

You may also check:How to resolve the algorithm Langton's ant step by step in the D programming language
You may also check:How to resolve the algorithm FizzBuzz step by step in the Elixir programming language
You may also check:How to resolve the algorithm Pangram checker step by step in the Java programming language
You may also check:How to resolve the algorithm Sum and product of an array step by step in the VBScript programming language
You may also check:How to resolve the algorithm Abelian sandpile model step by step in the Mathematica/Wolfram Language programming language