23 lines
542 B
Text
23 lines
542 B
Text
-- Returns list of prime factors for given number.
|
|
-- To overcome the limits of integers (signed 32-bit in Lingo),
|
|
-- the number can be specified as float (which works up to 2^53).
|
|
-- For the same reason, values in returned list are floats, not integers.
|
|
on getPrimeFactors (n)
|
|
f = []
|
|
f.sort()
|
|
c = sqrt(n)
|
|
i = 1.0
|
|
repeat while TRUE
|
|
i=i+1
|
|
if i>c then exit repeat
|
|
check = n/i
|
|
if bitOr(check,0)=check then
|
|
f.add(i)
|
|
n = check
|
|
c = sqrt(n)
|
|
i = 1.0
|
|
end if
|
|
end repeat
|
|
f.add(n)
|
|
return f
|
|
end
|