Inconsummate numbers in base 10: Difference between revisions
→{{header|ALGOL 68}}: Simplify - no need for the divisor sum table, find the consummate numbers while finding the sums, handle the stretch goal
(→{{header|Python}}: prepend Pascal. no divisor of a niven number) |
(→{{header|ALGOL 68}}: Simplify - no need for the divisor sum table, find the consummate numbers while finding the sums, handle the stretch goal) |
||
Line 31:
=={{header|ALGOL 68}}==
<syntaxhighlight lang="algol68">
BEGIN # find some incomsummate numbers: integers that cannot be expressed as #
# an integer divided by the sum of its digits #
# chosen because if we assume the 1000th #▼
FOR i FROM LWB consummate TO UPB consummate DO▼
# inconsummate number is <= 9 999, then the #▼
consummate[ i ] := FALSE▼
# maximum possible digit sum is 45 and so the #▼
OD;▼
# calculate the maximum number we must consider to find consummate #
# i.e.: 449 955 #▼
# numbers up to UPB consummate - which is 9 * the number of digits in #
INT max sum := 9;
INT v := UPB consummate;
WHILE ( v OVERAB 10 ) > 0 DO max sum +:= 9 OD;
INT max number = UPB consummate * max sum;
# construct the digit sums of the numbers up to max number #
# and find the consumate numbers, we start the loop from 10 to avoid #
INT tn := 1,
FOR n FROM 10
# d is comsummate #
FI;▼
sumd +:= 1
OD;▼
IF ( tn +:= 1 ) > 9 THEN
tn
IF ( hn +:= 1 ) > 9 THEN
hn := 0;
Line 64 ⟶ 72:
IF ( tt +:= 1 ) > 9 THEN
tt := 0;
IF ( ht +:= 1 ) > 9 THEN
ht := 0;
FI
FI
FI
FI
FI
▲ FI
▲ OD;
▲ [ 0 : max number ]BOOL consummate;
▲ FOR i FROM LWB consummate TO UPB consummate DO
▲ consummate[ i ] := FALSE
▲ OD;
IF i MOD dsum[ i ] = 0 THEN▼
FI
OD;
INT count := 0;
print( ( "The first 50 inconsummate numbers:", newline ) );
FOR i TO UPB consummate WHILE count <
IF NOT consummate[ i ] THEN
IF ( count +:= 1 ) < 51 THEN
print( ( whole( i, -6 ) ) );
IF count MOD 10 = 0 THEN print( ( newline ) ) FI
ELIF count = 1 000 OR count = 10 000 OR count = 100 000 THEN
print( ( "Inconsummate number ", whole( count,
, ": ", whole( i, -8 ), newline
)
FI
FI
Line 102 ⟶ 109:
441 443 461 466 471 476 482 483 486 488
491 492 493 494 497 498 516 521 522 527
Inconsummate number 1000: 6996
Inconsummate number 10000: 59853
Inconsummate number 100000: 536081
</pre>
|