How to resolve the algorithm Totient function step by step in the MAD programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Totient function step by step in the MAD programming language

Table of Contents

Problem Statement

The   totient   function is also known as:

The totient function:

If the totient number   (for N)   is one less than   N,   then   N   is prime.

Create a   totient   function and: Show all output here.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Totient function step by step in the MAD programming language

Source code in the mad programming language

            NORMAL MODE IS INTEGER
            BOOLEAN PRM

            INTERNAL FUNCTION(A,B)
            ENTRY TO REM.
            FUNCTION RETURN A-A/B*B
            END OF FUNCTION

            INTERNAL FUNCTION(NN)
            ENTRY TO TOTENT.
            N = NN
            TOT = N
            THROUGH STEP, FOR I=2, 2, I*I.G.N
            WHENEVER REM.(N,I).E.0
                THROUGH DIV, FOR N=N, 0, REM.(N,I).NE.0
DIV             N = N/I
                TOT = TOT-TOT/I
            END OF CONDITIONAL
            WHENEVER I.E.2, I=1
STEP        CONTINUE
            WHENEVER N.G.1, TOT = TOT-TOT/N
            FUNCTION RETURN TOT
            END OF FUNCTION

            COUNT = 0
            PRINT FORMAT HEADER
            THROUGH FRST25, FOR KN=1, 1, KN.G.25
            KTOT = TOTENT.(KN)
            PRM = KTOT.E.KN-1
            WHENEVER PRM, COUNT = COUNT + 1
FRST25      PRINT FORMAT NUMTOT,KN,KTOT,PRM

            PRINT FORMAT NUMPRM,25,COUNT

            THROUGH CNTPRM, FOR KN=26, 1, KN.G.100000
            KTOT = TOTENT.(KN)
            WHENEVER KTOT.E.KN-1, COUNT = COUNT+1
            WHENEVER KN.E.100 .OR. KN.E.1000 .OR. REM.(KN,10000).E.0,
          0     PRINT FORMAT NUMPRM,KN,COUNT
CNTPRM      CONTINUE

            VECTOR VALUES HEADER = $19H  N  TOTIENT  PRIME*$
            VECTOR VALUES NUMTOT = $I2,S2,I7,S2,I5*$
            VECTOR VALUES NUMPRM = $22HNUMBER OF PRIMES UP TO,I7,1H:,I6*$
            END OF PROGRAM

  

You may also check:How to resolve the algorithm Sum multiples of 3 and 5 step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Erdös-Selfridge categorization of primes step by step in the Nim programming language
You may also check:How to resolve the algorithm Empty program step by step in the XQuery programming language
You may also check:How to resolve the algorithm Letter frequency step by step in the Euphoria programming language
You may also check:How to resolve the algorithm Fibonacci n-step number sequences step by step in the PL/I programming language