Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
35
Task/M-bius-function/Pluto/m-bius-function.pluto
Normal file
35
Task/M-bius-function/Pluto/m-bius-function.pluto
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
local int = require "int"
|
||||
local fmt = require "fmt"
|
||||
|
||||
local function is_square_free(n)
|
||||
local i = 2
|
||||
local sq = i * i
|
||||
while sq <= n do
|
||||
if n % sq == 0 then return false end
|
||||
i = (i > 2) ? i + 2 : i + 1
|
||||
sq = i * i
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function mu(n)
|
||||
assert(n >= 1, "Argument must be a positive integer")
|
||||
if n == 1 then return 1 end
|
||||
local sq_free = is_square_free(n)
|
||||
local factors = int.factors(n)
|
||||
if sq_free and #factors % 2 == 0 then return 1 end
|
||||
if sq_free then return -1 end
|
||||
return 0
|
||||
end
|
||||
|
||||
print("The first 199 Möbius numbers are:")
|
||||
for i = 0, 9 do
|
||||
for j = 0, 19 do
|
||||
if i == 0 and j == 0 then
|
||||
io.write(" ")
|
||||
else
|
||||
fmt.write("% 3d ", mu(i * 20 + j))
|
||||
end
|
||||
end
|
||||
print()
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue