How to resolve the algorithm Mertens function step by step in the PL/I programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Mertens function step by step in the PL/I 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 PL/I programming language
Source code in the pl/i programming language
mertens: procedure options(main);
%replace MAX by 1000;
declare M(1:MAX) fixed binary(5);
declare (n, k) fixed binary(10);
declare (isZero, crossZero) fixed binary(8);
M(1) = 1;
do n = 2 to MAX;
M(n) = 1;
do k = 2 to n;
M(n) = M(n) - M(divide(n,k,10));
end;
end;
put skip list('The first 99 Mertens numbers are:');
put skip list(' ');
do n = 1 to 99;
put edit(M(n)) (F(3));
if mod(n,10) = 9 then put skip;
end;
isZero = 0;
crossZero = 0;
do n = 2 to MAX;
if M(n) = 0 then do;
isZero = isZero + 1;
if M(n-1) ^= 0 then
crossZero = crossZero + 1;
end;
end;
put skip list('Zeroes: ',isZero);
put skip list('Crossings:',crossZero);
end mertens;
You may also check:How to resolve the algorithm Zig-zag matrix step by step in the PL/I programming language
You may also check:How to resolve the algorithm Factors of an integer step by step in the PL/I programming language
You may also check:How to resolve the algorithm Averages/Mean time of day step by step in the PL/I programming language
You may also check:How to resolve the algorithm Arithmetic/Integer step by step in the PL/I programming language
You may also check:How to resolve the algorithm Best shuffle step by step in the PL/I programming language