PERFECT NUMBERS
A perfect number is one such that all its factors, including one but excluding
itself, add up to itself. For example, 6 is a perfect number since 6 has factors
1, 2, 3 and 6 and 1 + 2 + 3 = 6. In fact, 6 is the smallest perfect number.
Euclid proved in his Elements that a number of the form 2
p−1
(2
p
− 1) is
a perfect number if 2
p
− 1 is a prime number.
I used this fact to write a programme in Basic to find perfect numbers but
first we need a programme on prime numbers for checking if 2
p
− 1 is prime.
ready.
10 rem prime numbers
11 rem to calculate prime numbers up to a
20 input a
22 if a=2 then print"2": goto 100
25 print"2 3";
30 for i=2 to a
40 if i=a then 100
50 for d=2 to int(sqr(i)+2)
60 if i/d=int(i/d) then 90
70 next d
80 printi;
90 next i
100 end
So now let us see how we can use lines 40-60 to find perfect numbers.
10 rem perfect numbers
15 rem to calculate perfect numbers
20 input n
30 if n<6 then print "none":goto 200
35 if n=6 then print "6 only":goto 200
40 print"6";
45 for i=3 to 26
Originally published in Trigon (School Mathematics Journal of the Mathematical Asso-
ciation of South Australia) 21 (3), Nov. 1983, p. 7.