24 lines
719 B
Text
24 lines
719 B
Text
with javascript_semantics
|
|
sequence arithmetic = {1}
|
|
integer composite = 0
|
|
|
|
procedure get_arithmetics(integer nth)
|
|
integer n = arithmetic[$]+1
|
|
while length(arithmetic)<nth do
|
|
sequence divs = factors(n,1)
|
|
if remainder(sum(divs),length(divs))=0 then
|
|
composite += length(divs)>2
|
|
arithmetic &= n
|
|
end if
|
|
n += 1
|
|
end while
|
|
end procedure
|
|
|
|
get_arithmetics(100)
|
|
printf(1,"The first 100 arithmetic numbers are:\n%s\n",
|
|
{join_by(arithmetic,1,10," ",fmt:="%3d")})
|
|
constant fmt = "The %,dth arithmetic number is %,d up to which %,d are composite.\n"
|
|
for n in {1e3,1e4,1e5,1e6} do
|
|
get_arithmetics(n)
|
|
printf(1,fmt,{n,arithmetic[n],composite})
|
|
end for
|