Definition
A positive integer n is an arithmetic number if the average of its positive divisors is also an integer.

Clearly all odd primes p must be arithmetic numbers because their only divisors are 1 and p whose sum is even and hence their average must be an integer. However, the prime number 2 is not an arithmetic number because the average of its divisors is 1.5.

Example
30 is an arithmetic number because its 7 divisors are: [1, 2, 3, 5, 6, 10, 15, 30], their sum is 72 and average 9 which is an integer.

Task
Calculate and show here:

1. The first 100 arithmetic numbers.

2. The xth arithmetic number where x = 1,000 and x = 10,000.

3. How many of the first x arithmetic numbers are composite.

Note that, technically, the arithmetic number 1 is neither prime nor composite.

Stretch
Carry out the same exercise in 2. and 3. above for x = 100,000 and x = 1,000,000.

References
 Wikipedia: Arithmetic number
 OEIS:A003601 - Numbers n such that the average of the divisors of n is an integer




int N, ArithCnt, CompCnt, Div, DivCnt, Sum, Quot;
[Format(4, 0);
N:= 1;  ArithCnt:= 0;  CompCnt:= 0;
repeat  Div:= 1;  DivCnt:= 0;  Sum:= 0;
        loop    [Quot:= N/Div;
                if Quot < Div then quit;
                if Quot = Div and rem(0) = 0 then \N is a square
                    [Sum:= Sum+Quot;  DivCnt:= DivCnt+1;  quit];
                if rem(0) = 0 then
                    [Sum:= Sum + Div + Quot;
                    DivCnt:= DivCnt+2;
                    ];
                Div:= Div+1;
                ];
        if rem(Sum/DivCnt) = 0 then \N is arithmetic
            [ArithCnt:= ArithCnt+1;
            if ArithCnt <= 100 then
                [RlOut(0, float(N));
                if rem(ArithCnt/20) = 0 then CrLf(0);
                ];
            if DivCnt > 2 then CompCnt:= CompCnt+1;
            case ArithCnt of 1000, 10_000, 100_000, 1_000_000:
                [CrLf(0);
                IntOut(0, N);  ChOut(0, 9\tab\);
                IntOut(0, CompCnt);
                ]
            other;
            ];
        N:= N+1;
until   ArithCnt >= 1_000_000;
]