How to resolve the algorithm Amicable pairs step by step in the MAD programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Amicable pairs step by step in the MAD programming language

Table of Contents

Problem Statement

Two integers

N

{\displaystyle N}

and

M

{\displaystyle M}

are said to be amicable pairs if

N ≠ M

{\displaystyle N\neq M}

and the sum of the proper divisors of

N

{\displaystyle N}

(

s u m

(

p r o p D i v s

( N ) )

{\displaystyle \mathrm {sum} (\mathrm {propDivs} (N))}

)

= M

{\displaystyle =M}

as well as

s u m

(

p r o p D i v s

( M ) )

N

{\displaystyle \mathrm {sum} (\mathrm {propDivs} (M))=N}

.

1184 and 1210 are an amicable pair, with proper divisors:

Calculate and show here the Amicable pairs below 20,000; (there are eight).

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Amicable pairs step by step in the MAD programming language

Source code in the mad programming language

            NORMAL MODE IS INTEGER
            DIMENSION DIVS(20000)
            PRINT COMMENT $ AMICABLE PAIRS$
            
          R CALCULATE SUM OF DIVISORS OF N
            INTERNAL FUNCTION(N)
            ENTRY TO DIVSUM.
            DS = 0
            THROUGH SUMMAT, FOR DIVC=1, 1, DIVC.GE.N
SUMMAT      WHENEVER N/DIVC*DIVC.E.N, DS = DS+DIVC
            FUNCTION RETURN DS
            END OF FUNCTION
          
          R CALCULATE SUM OF DIVISORS FOR ALL NUMBERS 1..20000
            THROUGH MEMO, FOR I=1, 1, I.GE.20000
MEMO        DIVS(I) = DIVSUM.(I)

          R FIND ALL MATCHING PAIRS
            THROUGH CHECK, FOR I=1, 1, I.GE.20000
            THROUGH CHECK, FOR J=1, 1, J.GE.I
CHECK       WHENEVER DIVS(I).E.J .AND. DIVS(J).E.I, 
          0     PRINT FORMAT AMI,I,J
          
            VECTOR VALUES AMI = $I6,I6*$
            END OF PROGRAM

  

You may also check:How to resolve the algorithm Truth table step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Damm algorithm step by step in the Scala programming language
You may also check:How to resolve the algorithm Read a file line by line step by step in the OCaml programming language
You may also check:How to resolve the algorithm Pick random element step by step in the TUSCRIPT programming language
You may also check:How to resolve the algorithm Gapful numbers step by step in the Nim programming language