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.



Task

 Write a routine (function, procedure, whatever) to find the Mertens number for any positive integer x.
 Use that routine to find and display here, on this page, at least the first 99 terms in a grid layout. (Not just one long line or column of numbers.)
 Use that routine to find and display here, on this page, the number of times the Mertens function sequence is equal to zero in the range M(1) through M(1000).
 Use that routine to find and display here, on this page, the number of times the Mertens function sequence crosses zero in the range M(1) through M(1000). (Crossing defined as this term equal to zero but preceding term not.)


See also

 Wikipedia: Mertens function
 Wikipedia: Möbius function
 OEIS: A002321 - Mertens's function
 OEIS: A028442 - Numbers n such that Mertens's function M(n) is zero
 Numberphile - Mertens Conjecture
 Stackexchange: compute the mertens function

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



Related tasks

 Möbius function


            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 