Idoneal numbers: Difference between revisions
Content added Content deleted
(→{{header|ALGOL 68}}: tweak) |
(Added Action!) |
||
Line 21: | Line 21: | ||
;* [[O'Halloran numbers]] |
;* [[O'Halloran numbers]] |
||
=={{header|Action!}}== |
|||
<syntaxhighlight lang="action!"> |
|||
;;; find idoneal numbers - numbers that cannot be written as ab + bc + ac |
|||
;;; where 0 < a < b < c |
|||
;;; there are 65 known idoneal numbers |
|||
PROC Main() |
|||
CARD count, maxCount, n, n2, a, b, c, ab, sum |
|||
BYTE idoneal |
|||
count = 0 maxCount = 65 |
|||
n = 0 |
|||
n2 = n - 2 ; n2 will be 65534 = -2 |
|||
WHILE count < maxCount DO |
|||
n ==+ 1 |
|||
n2 ==+ 1 |
|||
idoneal = 1 |
|||
a = 0 |
|||
DO |
|||
a ==+ 1 |
|||
IF a >= n2 THEN |
|||
EXIT |
|||
ELSEIF idoneal = 0 THEN |
|||
EXIT |
|||
ELSE |
|||
b = a + 1 |
|||
DO |
|||
ab = a * b |
|||
IF ( ab + a + b ) > n OR idoneal = 0 THEN EXIT FI |
|||
c = b + 1 |
|||
DO |
|||
sum = ab + ( b * c ) + ( a * c ) |
|||
IF sum = n THEN |
|||
idoneal = 0 |
|||
EXIT |
|||
ELSEIF sum > n THEN |
|||
EXIT |
|||
ELSE |
|||
c ==+ 1 |
|||
FI |
|||
OD |
|||
b ==+ 1 |
|||
OD |
|||
FI |
|||
OD |
|||
IF idoneal THEN |
|||
Put(' ) |
|||
IF n < 10 THEN Put(' ) FI |
|||
IF n < 100 THEN Put(' ) FI |
|||
IF n < 1000 THEN Put(' ) FI |
|||
PrintC( n ) |
|||
count ==+ 1 |
|||
IF count MOD 13 = 0 THEN PutE() FI |
|||
FI |
|||
OD |
|||
RETURN |
|||
</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> |
|||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |