(phixonline)-->
with javascript_semantics
sequence arithmetic = {1}
integer composite = 0
function get_arithmetic(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
return arithmetic[nth]
end function
{} = get_arithmetic(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
integer nth = get_arithmetic(n)
printf(1,fmt,{n,nth,composite})
end for