Möbius function: Difference between revisions

Content added Content deleted
(Edited code to meet task requirements.)
(Added XPL0 example.)
Line 1,750: Line 1,750:
</pre>
</pre>


=={{header|XPL0}}==
<lang XPL0>func Mobius(N);
int N, Cnt, F, K;
[Cnt:= 0;
F:= 2; K:= 0;
repeat if rem(N/F) = 0 then
[Cnt:= Cnt+1;
N:= N/F;
K:= K+1;
if K >= 2 then return 0;
]
else [F:= F+1; K:= 0];
until F > N;
return if Cnt&1 then -1 else 1;
];

int N;
[Format(3, 0);
Text(0, " ");
for N:= 1 to 199 do
[RlOut(0, float(Mobius(N)));
if rem(N/20) = 19 then CrLf(0);
];
]</lang>

{{out}}
<pre>
1 -1 -1 0 -1 1 -1 0 0 1 -1 0 -1 1 1 0 -1 0 -1
0 1 1 -1 0 0 1 0 0 -1 -1 -1 0 1 1 1 0 -1 1 1
0 -1 -1 -1 0 0 1 -1 0 0 0 1 0 -1 0 1 0 1 1 -1
0 -1 1 0 0 1 -1 -1 0 1 -1 -1 0 -1 1 0 0 1 -1 -1
0 0 1 -1 0 1 1 1 0 -1 0 1 0 1 1 1 0 -1 0 0
0 -1 -1 -1 0 -1 1 -1 0 -1 -1 1 0 -1 -1 1 0 0 1 1
0 0 1 1 0 0 0 -1 0 1 -1 -1 0 1 1 0 0 -1 -1 -1
0 1 1 1 0 1 1 0 0 -1 0 -1 0 0 -1 1 0 -1 1 1
0 1 0 -1 0 -1 1 -1 0 0 -1 0 0 -1 -1 0 0 1 1 -1
0 -1 -1 1 0 1 -1 1 0 0 -1 -1 0 -1 1 -1 0 -1 0 -1
</pre>


=={{header|Yabasic}}==
=={{header|Yabasic}}==
Line 1,774: Line 1,812:
return -1
return -1
end sub</lang>
end sub</lang>



=={{header|zkl}}==
=={{header|zkl}}==