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




LET n = 1
DO
   LET div = 1
   LET divcnt = 0
   LET sum = 0
   DO
      LET quot = n/div
      IF quot < div THEN EXIT DO
      IF REMAINDER(n, div) = 0 THEN
         IF quot = div THEN            !n IS a square
            LET sum = sum+quot
            LET divcnt = divcnt+1
            EXIT DO
         ELSE
            LET sum = sum+div+quot
            LET divcnt = divcnt+2
         END IF
      END IF
      LET div = div+1
   LOOP
 
   IF REMAINDER(sum, divcnt) = 0 THEN  !n IS arithmetic
      LET arithcnt = arithcnt+1
      IF arithcnt <= 100 THEN
         PRINT  USING "####": n;
         IF REMAINDER(arithcnt, 20) = 0 THEN PRINT
      END IF
      IF divcnt > 2 THEN LET compcnt = compcnt+1
      SELECT CASE arithcnt
      CASE 1000
           PRINT
           PRINT  USING "The #######th arithmetic number is #####,### up to which ###,### are composite.": arithcnt, n, compcnt
      CASE 10000, 100000, 1000000
           PRINT  USING "The #######th arithmetic number is #####,### up to which ###,### are composite.": arithcnt, n, compcnt
      CASE ELSE
           REM
      END SELECT
   END IF
   LET n = n+1
LOOP UNTIL arithcnt >= 1000000
END