RosettaCodeData/Task/M-bius-function/Gambas/m-bius-function.gambas

28 lines
493 B
Plaintext

Public Sub Main()
Dim outstr As String = " . "
For i As Integer = 1 To 200
If mobius(i) >= 0 Then outstr &= " "
outstr &= Str(mobius(i)) & " "
If i Mod 10 = 9 Then
Print outstr
outstr = ""
End If
Next
End
Function mobius(n As Integer) As Integer
If n = 1 Then Return 1
For d As Integer = 2 To Int(Sqr(n))
If n Mod d = 0 Then
If n Mod (d * d) = 0 Then Return 0
Return -mobius(n / d)
End If
Next
Return -1
End Function