25 lines
655 B
Text
25 lines
655 B
Text
mobius: function [n][
|
|
if n=0 -> return ""
|
|
if n=1 -> return 1
|
|
f: factors.prime n
|
|
|
|
if f <> unique f -> return 0
|
|
if? odd? size f -> return neg 1
|
|
else -> return 1
|
|
]
|
|
|
|
mertens: function [z][sum map 1..z => mobius]
|
|
|
|
print "The first 99 Mertens numbers are:"
|
|
loop split.every:20 [""]++map 1..99 => mertens 'a [
|
|
print map a 'item -> pad to :string item 2
|
|
]
|
|
|
|
print ""
|
|
|
|
mertens1000: map 1..1000 => mertens
|
|
print ["Times M(x) is zero between 1 and 1000:" size select mertens1000 => zero?]
|
|
|
|
crossed: new 0
|
|
fold mertens1000 [a,b][if and? zero? b not? zero? a -> inc 'crossed, b]
|
|
print ["Times M(x) crosses zero between 1 and 1000:" crossed]
|