43 lines
1.1 KiB
Plaintext
43 lines
1.1 KiB
Plaintext
% Generate Mertens numbers up to a given limit
|
|
mertens = proc (limit: int) returns (array[int])
|
|
M: array[int] := array[int]$fill(1,limit,0)
|
|
M[1] := 1
|
|
for n: int in int$from_to(2,limit) do
|
|
M[n] := 1
|
|
for k: int in int$from_to(2,n) do
|
|
M[n] := M[n] - M[n/k]
|
|
end
|
|
end
|
|
return (M)
|
|
end mertens
|
|
|
|
start_up = proc ()
|
|
max = 1000
|
|
|
|
po: stream := stream$primary_output()
|
|
M: array[int] := mertens(max)
|
|
|
|
stream$putl(po, "The first 99 Mertens numbers are:")
|
|
for y: int in int$from_to_by(0,90,10) do
|
|
for x: int in int$from_to(0,9) do
|
|
stream$putright(po, int$unparse(M[x+y]), 3)
|
|
except when bounds:
|
|
stream$putright(po, "", 3)
|
|
end
|
|
end
|
|
stream$putl(po, "")
|
|
end
|
|
|
|
eqz: int := 0
|
|
crossz: int := 0
|
|
for i: int in int$from_to(2,max) do
|
|
if M[i]=0 then
|
|
eqz := eqz + 1
|
|
if M[i-1]~=0 then crossz := crossz + 1 end
|
|
end
|
|
end
|
|
|
|
stream$putl(po, "M(N) is zero " || int$unparse(eqz) || " times.")
|
|
stream$putl(po, "M(N) crosses zero " || int$unparse(crossz) || " times.")
|
|
end start_up
|