34 lines
1007 B
Plaintext
34 lines
1007 B
Plaintext
program arithmetic_numbers;
|
|
[divsum, divcount] := calcdivsums(130000);
|
|
|
|
print("First 100 arithmetic numbers:");
|
|
|
|
loop for nth in [1..100000] do
|
|
loop until divsum(num) mod divcount(num) = 0 do num +:= 1; end loop;
|
|
comp +:= if num>1 and divsum(num) /= num+1 then 1 else 0 end if;
|
|
|
|
if nth <= 100 then
|
|
putchar(rpad(str num, 5));
|
|
if nth mod 10 = 0 then print(); end if;
|
|
end if;
|
|
|
|
if nth in [1000, 10000, 100000] then
|
|
print("The " + nth + "th arithmetic number is " + num + ".");
|
|
print("Of the first " + nth + " arithmetic numbers, " +
|
|
comp + " are composite.");
|
|
end if;
|
|
end loop;
|
|
|
|
proc calcdivsums(m);
|
|
sums := [];
|
|
counts := [];
|
|
loop for d in [1..m] do
|
|
loop for n in [d, d*2..m] do
|
|
sums(n) +:= d;
|
|
counts(n) +:= 1;
|
|
end loop;
|
|
end loop;
|
|
return [sums, counts];
|
|
end proc;
|
|
end program;
|