Cuban primes: Difference between revisions

Line 1,358:
 
=={{header|Lua}}==
 
{{incorrect|Lua| <br> The output for the 100,000<sup>th</sup> cuban prime is incorrect. <br> (Possible integer overflow) <br><br>}}
 
{{trans|D}}
<lang lua>local primes = {3, 5}
Line 1,378 ⟶ 1,375:
v = v + u
local mx = math.ceil(math.sqrt(v))
--for _,item in pairs(primes) do -- why: latent traversal bugfix (and performance)
for _,item in ipairs(primes) do
if item > mx then
break
Line 1,392 ⟶ 1,390:
c = c + 1
if showEach then
--local z = primes[table.getn(primes)] + 2 -- why: modernize (deprecated)
local z = primes[#primes] + 2
while z <= v - 2 do
local fnd = false
--for _,item in pairs(primes) do -- why: latent traversal bugfix (and performance)
for _,item in ipairs(primes) do
if item > mx then
break
Line 1,427:
end
end
--print(string.format("\nThe %dth%s is %17d", c, tn, v))</lang> -- why: correcting reported inaccuracy in output
print(string.format("\nThe %dth%s is %.0f", c, tn, v))</lang>
{{out}}
The final test seems to have overextended the numeric limits. Everything prior still looks correct.
<pre>The first 200 cuban primes
7 19 37 61 127 271 331 397 547 631
Line 1,453:
 
Progress to the 100000th cuban prime: ..................................................
The 100000th cuban prime is -21474836481792617147127</pre>
 
=={{header|Maple}}==
Anonymous user