the function
function PrimeFactors(Number)
local Factors = {}
local AllFactors = {}
local FactorCount = {}
local Factor = 2
local Sign = math.sign(Number)
Number = math.abs(Number)
local function AddCount(Number)
if FactorCount[Number] then
FactorCount[Number] += 1
else
FactorCount[Number] = 1
table.insert(AllFactors, Number)
end
end
while Factor^2 <= Number do
while Number % Factor == 0 and Number > Factor do
table.insert(Factors, Sign * Factor)
AddCount(Sign * Factor)
Number /= Factor
end
Factor += (Factor == 2 and 1 or 2)
end
table.insert(Factors, Sign * Number)
AddCount(Sign * Number)
return Factors, AllFactors, FactorCount
end
ok so the function works very well, but I do have a slight problem
when I put in 10^22 it will output with this
ignore the other two tables, I showed the most important one
the key is the prime factor and the value is the number of times it shows up
now look at 10^23
it SHOULD be 23 2’s and 23 5’s or {[2] = 23, [5] = 23}
, instead it shows prime numbers that are incorrect
can I have help on this?
thanks