local x = 100
local g = 0
local prost = 2
local sq_x = math.sqrt(x) + 1
sq_x = math.floor(sq_x)
while (prost < sq_x) do
print("P: "..prost)
for i = prost, sq_x, 1 do
if ( x % i == 0 ) then
g = x / i
sq_x = math.sqrt(g) + 1
sq_x = math.floor(sq_x)
end
end
end
你的代码不容易修复。有很多细节是相互关联的。例如:
prost
总是等于二。而且g
它永远不会低于五十。也就是说,条件中的两个数字while
(thisprost
和sq_x
,取决于g
)永远不会收敛,并且循环将是永恒的。像这样的东西应该有效。在这里,在外部的每次迭代中,
while
会发生两件事:p
它必然增加,并且sqrt_n
必然减少。也就是说,循环总是结束。