Mertens function: Difference between revisions

Add CLU
(Added solution for Action!)
(Add CLU)
Line 914:
M(n) crosses zero 59 times for 1 <= n <= 1000.
</pre>
 
=={{header|CLU}}==
<lang clu>% 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</lang>
{{out}}
<pre>The first 99 Mertens numbers are:
1 0 -1 -1 -2 -1 -2 -2 -2
-1 -2 -2 -3 -2 -1 -1 -2 -2 -3
-3 -2 -1 -2 -2 -2 -1 -1 -1 -2
-3 -4 -4 -3 -2 -1 -1 -2 -1 0
0 -1 -2 -3 -3 -3 -2 -3 -3 -3
-3 -2 -2 -3 -3 -2 -2 -1 0 -1
-1 -2 -1 -1 -1 0 -1 -2 -2 -1
-2 -3 -3 -4 -3 -3 -3 -2 -3 -4
-4 -4 -3 -4 -4 -3 -2 -1 -1 -2
-2 -1 -1 0 1 2 2 1 1 1
M(N) is zero 92 times.
M(N) crosses zero 59 times.</pre>
 
=={{header|COBOL}}==
2,114

edits