Möbius function: Difference between revisions

no edit summary
(Added XPL0 example.)
No edit summary
Line 571:
0 -1 -1 1 0 1 -1 1 0 0
-1 -1 0 -1 1 -1 0 -1 0 -1</pre>
 
 
=={{header|FutureBasic}}==
<lang futurebasic>
 
include "NSLog.incl"
 
local fn IsPrime( n as NSInteger ) as Boolean
'~'1
Boolean i, result
 
if ( n < 2 ) then result = NO : exit fn
 
for i = 2 to n + 1
if ( i * i <= n ) and ( n mod i == 0 )
result = NO : exit fn
end if
next
result = YES
end fn = result
 
 
local fn Mobius( n as NSInteger ) as NSInteger
'~'1
NSInteger i, p = 0, result = 0
 
if ( n == 1 ) then result = 1 : exit fn
 
for i = 1 to n + 1
if ( n mod i == 0 ) and( fn IsPrime( i ) == YES )
if ( n mod ( i * i) == 0 )
result = 0 : exit fn
else
p++
end if
end if
next
if( p mod 2 != 0 )
result = -1 : exit fn
else
result = 1 : exit fn
end if
end fn = result
 
window 1
 
NSInteger i
 
printf @"First 200 terms of Mobius swquence:"
 
for i = 1 to 100
printf @"%2ld\t", fn Mobius(i)
if ( i mod 20 == 0 ) then print
next
 
HandleEvents
</lang>
{{output}}
<pre>
First 200 terms of Mobius swquence:
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
</pre>
 
 
=={{header|Go}}==
715

edits