### Problem
Description

Here's a program to let you start exploring the
interesting topic of **Perfect, Amicable, **and** Sociable**
numbers. They are defined by the sums of their aliquot divisors. The
**
aliquot divisors** of a number are all of its divisors except the number itself.
The ** aliquot sum** is the sum of the aliquot divisors so, for example, the aliquot
divisors of 12 are 1, 2, 3, 4, and 6 and it's aliquot sum is 16.
A number whose aliquot sum equals its value is a PERFECT number (6 for example). If we
denote the aliquot sum by ASUM, then the condition for a perfect number is
ASum(N)=N. Numbers A and B with the property that ASum(A)=B and ASum(B)=A are called AMICABLE numbers.
Longer cycles exist, these are sometimes called SOCIABLE numbers. For example
ASum(A)=B, ASum(B)=C, ASum(C)=A would be a Sociable cycle of length 3.

**AliquotSums i**s a program that will let you search
for Perfect, Amicable and Sociable numbers, including one remarkable cycle 28
numbers in length.

###

Background
& Techniques

The idea for this program came from a chapter in *Recreations in the
Theory of Numbers* (Albert Beiler, Dover Publications). In
case you're wondering about that word ...

**
****al·i·quot** (àl¹î-kwòt´,
-kwet)
*Mathematics.* *adjective *Of, relating to, or denoting an exact
divisor or factor of a quantity, especially of an integer. *noun *
An aliquot part. [Latin *aliquot*, some number : *alius*, some + *quot*, how
many.]

Perfect numbers are few and far between.
The first 3 are easily found, the 4th can be found if you set the upper
limit high enough, it's up around 3,500,000 as I recall. Amicable pairs
are fairly common but search times get long when we get up in the
millions.

**TIntEdit** numeric edit components are used to collect some
values (start and stop values, a maximum cycle length to check and a maximum
sum) that control each run. TIntEdit
is available here. You will need to install it before compiling AliquotSums
or change TIntEdits to TEdits and write your own code to check and convert
edit text value to Int64 values.

AliquotSums uses the **Primes** instance of the **TPrimes** class
(both defined in
the **U_Primes** unit) to factor each number to be tested. One
problem is that we need to find all factors and ** Primes** returns only the prime
factors. Fortunately the mathematicians come through again with an equation
to calculate the sum of all factors without enumerating them. For
each prime factor,** p** that occurs ** e** times the sum of factors it contributes
is one less than (p^{e+1}-1)/(p-1). So for example,
if a number is divisible by 8 but not 16, the prime factor ** 2** occurs ** 3**
times. and **(2**^{3+1}-1)/(2-1) = 15 = 1+2+4+8.
The product of these expressions for all prime factors is the sum of
all factors. I played around with a few samples, and sure enough, it
works, but I'm not smart enough to explain why in simple
terms. So the function AliquotSum computes this for each trial
number. The new ** TIntList** integer list class saves the results, and each sum becomes the
input for the next calculation. Each is checked against the first list
entry checking to see if we are back where we started. If so a cycle has been
found and we can display it and go on the next.

Lots of duplicates will show up, so each displayed
value is saved in a second **TIntList** and aliquot cycles which begin with
an already displayed value are skipped.

There are one other interesting feature of
the program: The **FormActivate**
method shows how to add margins to a **TMemo** using an **EM_SetMargins**
message.

The** U_IntList** unit containing the TIntList class
is included in the source download. You can read more about and
download a test project here.

### Running/Exploring the Program