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

Published on 12 May 2024 09:40 PM

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

Table of Contents

Problem Statement

The Mertens function M(x) is the count of square-free integers up to x that have an even number of prime factors, minus the count of those that have an odd number. It is an extension of the Möbius function. Given the Möbius function μ(n), the Mertens function M(x) is the sum of the Möbius numbers from n == 1 through n == x.

This is not code golf.   The stackexchange link is provided as an algorithm reference, not as a guide.

Let's start with the solution:

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

Source code in the mad programming language

            NORMAL MODE IS INTEGER
            DIMENSION M(1000)
                  
            M(1) = 1
            THROUGH GENMRT, FOR N=2, 1, N.G.1000
            M(N) = 1
            THROUGH GENMRT, FOR K=2, 1, K.G.N
GENMRT      M(N) = M(N) - M(N/K)
            
            PRINT COMMENT $ FIRST 99 MERTEN NUMBERS ARE$
            VECTOR VALUES F9 = $S3,9(I2,S1)*$
            VECTOR VALUES F10 = $10(I2,S1)*$
            
            PRINT FORMAT F9, M(1), M(2), M(3), M(4), M(5), M(6),
          0                  M(7), M(8), M(9)
          
            THROUGH SHOW, FOR N=10, 10, N.GE.100
SHOW        PRINT FORMAT F10, M(N), M(N+1), M(N+2), M(N+3), M(N+4),
          0   M(N+5), M(N+6), M(N+7), M(N+8), M(N+9), M(N+10)
          
            ZERO = 0
            CROSS = 0
            THROUGH ZC, FOR N=1, 1, N.G.1000
            WHENEVER M(N).E.0, ZERO = ZERO + 1
ZC          WHENEVER M(N).E.0 .AND. M(N-1).NE.0, CROSS = CROSS + 1

            VECTOR VALUES FZ = $13HM(N) IS ZERO ,I2,S1,5HTIMES*$
            PRINT FORMAT FZ, ZERO
            
            VECTOR VALUES FC = $18HM(N) CROSSES ZERO ,I2,S1,5HTIMES*$
            PRINT FORMAT FC, CROSS
            
            END OF PROGRAM

  

You may also check:How to resolve the algorithm Binary digits step by step in the Tcl programming language
You may also check:How to resolve the algorithm Averages/Arithmetic mean step by step in the MiniScript programming language
You may also check:How to resolve the algorithm Idiomatically determine all the lowercase and uppercase letters step by step in the Prolog programming language
You may also check:How to resolve the algorithm Echo server step by step in the D programming language
You may also check:How to resolve the algorithm Distributed programming step by step in the JavaScript programming language