Idoneal numbers: Difference between revisions
Content added Content deleted
(→{{header|Julia}}: Trans) |
(Added Lua) |
||
Line 686: | Line 686: | ||
<pre> |
<pre> |
||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 15, 16, 18, 21, 22, 24, 25, 28, 30, 33, 37, 40, 42, 45, 48, 57, 58, 60, 70, 72, 78, 85, 88, 93, 102, 105, 112, 120, 130, 133, 165, 168, 177, 190, 210, 232, 240, 253, 273, 280, 312, 330, 345, 357, 385, 408, 462, 520, 760, 840, 1320, 1365, 1848] |
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 15, 16, 18, 21, 22, 24, 25, 28, 30, 33, 37, 40, 42, 45, 48, 57, 58, 60, 70, 72, 78, 85, 88, 93, 102, 105, 112, 120, 130, 133, 165, 168, 177, 190, 210, 232, 240, 253, 273, 280, 312, 330, 345, 357, 385, 408, 462, 520, 760, 840, 1320, 1365, 1848] |
||
</pre> |
|||
=={{header|Lua}}== |
|||
{{Trans|Action!}} |
|||
<syntaxhighlight lang="lua"> |
|||
do -- find idoneal numbers - numbers that cannot be written as ab + bc + ac |
|||
-- where 0 < a < b < c |
|||
-- there are 65 known idoneal numbers |
|||
local count = 0 |
|||
local maxCount = 65 |
|||
local n = 0 |
|||
while count < maxCount do |
|||
n = n + 1 |
|||
local idoneal = true |
|||
local a = 1 |
|||
while ( a + 2 ) < n and idoneal do |
|||
local b = a + 1 |
|||
repeat |
|||
local ab = a * b |
|||
local sum = 0 |
|||
if ab < n then |
|||
local c = math.floor( ( n - ab ) / ( a + b ) ) |
|||
sum = ab + ( c * ( b + a ) ) |
|||
if c > b and sum == n then |
|||
idoneal = false |
|||
end |
|||
b = b + 1 |
|||
end |
|||
until sum > n or idoneal == 0 or ab >= n |
|||
a = a + 1 |
|||
end |
|||
if idoneal then |
|||
count = count + 1 |
|||
io.write( string.format( " %4d", n ) ) |
|||
if count % 13 == 0 then io.write( "\n" ) end |
|||
end |
|||
end |
|||
end |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
1 2 3 4 5 6 7 8 9 10 12 13 15 |
|||
16 18 21 22 24 25 28 30 33 37 40 42 45 |
|||
48 57 58 60 70 72 78 85 88 93 102 105 112 |
|||
120 130 133 165 168 177 190 210 232 240 253 273 280 |
|||
312 330 345 357 385 408 462 520 760 840 1320 1365 1848 |
|||
</pre> |
</pre> |
||