RosettaCodeData/Task/Count-in-factors/Lua/count-in-factors.lua
2026-02-01 16:33:20 -08:00

17 lines
355 B
Lua

local function factorize( n )
if n == 1 then return {1} end
local k, res = 2, {}
while n > 1 do
while n % k == 0 do
res[#res+1] = k
n = n / k
end
k = k + 1
end
return res
end
for i = 1, 22 do
print( string.format( "%2d", i ) .. ": " .. table.concat( factorize( i ), " * " ) )
end