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

Source code in the xpl0 programming language

func MinMaxPrimeFactors(N);
int N, Min, Max, P;     \(Min and Max must be in order shown)
[Min:= 1;  Max:= 1;
if (N&1) = 0 then
    [while (N&1) = 0 do
        N:= N>>1;
    Min:= 2;
    Max:= 2;
    ];
P:= 3;
while P*P <= N do
    [if rem(N/P) = 0 then
        [while rem(N/P) = 0 do
            N:= N/P;
        if Min = 1 then
            Min:= P;
        Max:= P;
        ];
    P:= P+2;
    ];
if N > 1 then
    [if Min = 1 then
        Min:= N;
    Max:= N;
    ];
return @Min;     \risky
];

int N, P;
[Text(0, "Product of smallest and greatest prime factors of N for 1 to 100:^m^j");
Format(5, 0);
for N:= 1 to 100 do
    [P:= MinMaxPrimeFactors(N);
    RlOut(0, float(P(0)*P(1)));
    if rem(N/10) = 0 then CrLf(0);
    ]
]

  

You may also check:How to resolve the algorithm Department numbers step by step in the Fermat programming language
You may also check:How to resolve the algorithm Attractive numbers step by step in the Comal programming language
You may also check:How to resolve the algorithm Arithmetic evaluation step by step in the Ruby programming language
You may also check:How to resolve the algorithm Descending primes step by step in the RPL programming language
You may also check:How to resolve the algorithm GUI component interaction step by step in the Racket programming language