2026-04-30 12:34:36 -04:00
|
|
|
-- 3 Mar 2026
|
2026-02-01 16:33:20 -08:00
|
|
|
include Setting
|
2025-06-11 20:16:52 -04:00
|
|
|
arg xx
|
|
|
|
|
if xx = '' then
|
|
|
|
|
xx = 99
|
2023-07-01 11:58:00 -04:00
|
|
|
|
2025-06-11 20:16:52 -04:00
|
|
|
say 'MERTENS FUNCTION'
|
|
|
|
|
say version
|
|
|
|
|
say
|
|
|
|
|
call Tasks1 xx
|
2026-04-30 12:34:36 -04:00
|
|
|
call Timer 'R'
|
2025-06-11 20:16:52 -04:00
|
|
|
call Tasks2 xx
|
2026-04-30 12:34:36 -04:00
|
|
|
call Timer 'R'
|
2025-06-11 20:16:52 -04:00
|
|
|
call Tasks3 xx
|
2026-04-30 12:34:36 -04:00
|
|
|
call Timer 'R'
|
2025-06-11 20:16:52 -04:00
|
|
|
exit
|
|
|
|
|
|
|
|
|
|
Tasks1:
|
2026-04-30 12:34:36 -04:00
|
|
|
procedure expose squa. memo.
|
2025-06-11 20:16:52 -04:00
|
|
|
arg xx
|
|
|
|
|
say 'Tasks using Sieve...'
|
|
|
|
|
call Squarefrees 2*xx
|
|
|
|
|
if xx < 100 then
|
|
|
|
|
say 'M1 thru M'xx
|
|
|
|
|
e = 0; o = 0; a = 0; b = 0
|
|
|
|
|
n = 1; s = squa.1; p = s
|
|
|
|
|
do i = 1 to xx
|
|
|
|
|
if s <= i then do
|
|
|
|
|
if s = 1 then
|
|
|
|
|
f = 0
|
|
|
|
|
else
|
|
|
|
|
f = Factors(s)
|
|
|
|
|
e = e+Even(f); o = o+Odd(f); m = e-o
|
|
|
|
|
n = n+1; s = squa.n
|
|
|
|
|
end
|
|
|
|
|
if xx < 100 & i < 100 then do
|
|
|
|
|
call Charout ,Right(m,3)
|
|
|
|
|
if i//10 = 0 then
|
|
|
|
|
say
|
|
|
|
|
end
|
|
|
|
|
if m = 0 then do
|
|
|
|
|
a = a+1
|
|
|
|
|
if p <> 0 then
|
|
|
|
|
b = b + 1
|
|
|
|
|
end
|
|
|
|
|
p = m
|
|
|
|
|
end
|
|
|
|
|
say
|
|
|
|
|
say 'M1 thru M'xx 'equals zero' a 'times'
|
|
|
|
|
say 'M1 thru M'xx 'crosses zero' b 'times'
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
Tasks2:
|
2026-04-30 12:34:36 -04:00
|
|
|
procedure expose squa. memo.
|
2025-06-11 20:16:52 -04:00
|
|
|
arg xx
|
|
|
|
|
say 'Tasks using Moebius function...'
|
|
|
|
|
if xx < 100 then
|
|
|
|
|
say 'M1 thru M'xx
|
|
|
|
|
e = 0; o = 0; a = 0; b = 0
|
|
|
|
|
s = 0
|
|
|
|
|
do i = 1 to xx
|
|
|
|
|
s = s+Moebius(i)
|
|
|
|
|
if xx < 100 & i < 100 then do
|
|
|
|
|
call Charout ,Right(s,3)
|
|
|
|
|
if i//10 = 0 then
|
|
|
|
|
say
|
|
|
|
|
end
|
|
|
|
|
if s = 0 then do
|
|
|
|
|
a = a+1
|
|
|
|
|
if p <> 0 then
|
|
|
|
|
b = b + 1
|
|
|
|
|
end
|
|
|
|
|
p = s
|
|
|
|
|
end
|
|
|
|
|
say
|
|
|
|
|
say 'M1 thru M'xx 'equals zero' a 'times'
|
|
|
|
|
say 'M1 thru M'xx 'crosses zero' b 'times'
|
2023-07-01 11:58:00 -04:00
|
|
|
return
|
2025-06-11 20:16:52 -04:00
|
|
|
|
|
|
|
|
Tasks3:
|
2026-04-30 12:34:36 -04:00
|
|
|
procedure expose squa. memo.
|
2025-06-11 20:16:52 -04:00
|
|
|
arg xx
|
|
|
|
|
say 'Tasks using Squarefree function...'
|
|
|
|
|
if xx < 100 then
|
|
|
|
|
say 'M1 thru M'xx
|
|
|
|
|
e = 0; o = 0; a = 0; b = 0
|
|
|
|
|
do s = 1 to xx
|
|
|
|
|
if Squarefree(s) then do
|
|
|
|
|
if s = 1 then
|
|
|
|
|
f = 0
|
|
|
|
|
else
|
|
|
|
|
f = Factors(s)
|
|
|
|
|
e = e+Even(f); o = o+Odd(f); m = e-o
|
|
|
|
|
end
|
|
|
|
|
if xx < 100 & s < 100 then do
|
|
|
|
|
call Charout ,Right(m,3)
|
|
|
|
|
if s//10 = 0 then
|
|
|
|
|
say
|
|
|
|
|
end
|
|
|
|
|
if m = 0 then do
|
|
|
|
|
a = a+1
|
|
|
|
|
if p <> 0 then
|
|
|
|
|
b = b + 1
|
|
|
|
|
end
|
|
|
|
|
p = m
|
|
|
|
|
end
|
|
|
|
|
say
|
|
|
|
|
say 'M1 thru M'xx 'equals zero' a 'times'
|
|
|
|
|
say 'M1 thru M'xx 'crosses zero' b 'times'
|
|
|
|
|
return
|
|
|
|
|
|
2026-04-30 12:34:36 -04:00
|
|
|
-- Squarefrees; Factors; Even; Odd; Moebius; Timer
|
2026-02-01 16:33:20 -08:00
|
|
|
include Math
|