-- Prime factors
print "Enter a positive integer"
local N
repeat N = io.read "*n" until N > 0
local bar = "-------------"
print (bar)

local factors = \ (n)
 local p, m = { }, { } -- prime factors, multiplicities
 for t = 2,3,1 do  -- deal with 2,3 separately
   if n%t == 0 then
     p[1 + #p] = t; m[1 + #m] = 1; n //= t
     while n%t == 0 do
        m[#m] += 1; n //= t
     end -- while
   end -- if
 end -- for
 local t = 3 -- test factor
 while n > 1 do
    t += 2
    if n%t == 0 then
       p[1 + #p] = t; m[1 + #m] = 1; n //= t
       while n%t == 0 do
          m[#m] += 1; n //= t
       end
     else
     if t*t > n then  -- too big, so n is a prime
        p[1 + #p] = n; m[1 + #m] = 1; n = 1
     end -- if
     end -- if
 end -- while
  => p, m
end -- function

local p, m = factors (N)
local write in io
write (tostring (N), " = ")
local k = #p
for i = 1, k do
   local e = m[i]
   write (tostring (p[i]))
   if e > 1 then write ("^", tostring (e)) end -- if
   if i < k then write "*" end -- if
end -- for

print ""
print (bar)