Numbers which are the cube roots of the product of their proper divisors: Difference between revisions

Added Lua version
(added julia entry)
(Added Lua version)
Line 771:
50000th: 223735
</pre>
 
=={{header|Lua}}==
The OEIS page gives a formula of "1 together with numbers with 8 divisors", so that's what we test.
<syntaxhighlight lang="lua">function is_1_or_has_eight_divisors (n)
if n == 1 then return true end
local divCount, sqr = 2, math.sqrt(n)
for d = 2, sqr do
if n % d == 0 then
divCount = d == sqr and divCount + 1 or divCount + 2
end
if divCount > 8 then return false end
end
return divCount == 8
end
 
-- First 50
local count, x = 1, 0
while count <= 50 do
x = x + 1
if is_1_or_has_eight_divisors(x) then
io.write(x .. " ")
count = count + 1
end
end
 
-- 500th, 5,000th and 50,000th
while count <= 50000 do
x = x + 1
if is_1_or_has_eight_divisors(x) then
if count == 500 then print("\n\n500th: " .. x) end
if count == 5000 then print("5,000th: " .. x) end
count = count + 1
end
end
print("50,000th: " .. x)</syntaxhighlight>
{{out}}
<pre>1 24 30 40 42 54 56 66 70 78 88 102 104 105 110 114 128 130 135 136 138 152 154 165 170 174 182 184 186 189 190 195 222 230 231 232 238 246 248 250 255 258 266 273 282 285 286 290 296 297
 
500th: 2526
5,000th: 23118
50,000th: 223735</pre>
 
=={{header|Pascal}}==
31

edits