10REM PERFECT NUMBERS
20*TV 255,0
30MODE4
40VDU 19,0,4,0,0,0
50CLS
60PRINT"This program searches for per
fect numbers on the assumption tha
t they follow the same mathematical
expression as the highest known perfect
number."
70PRINT:PRINT"Whenever a perfect numb
er is found it is printed on screen and
to the printer before continuing the s
earch for the next number."
80PRINT:PRINT"Be warned that the fift
h perfect number will take quite some ti
me to find. Probably longer than 10
days !!":PRINT
90PRINT"Please prepare your printer..
."
100PRINT:PRINT"...then press any key t
o continue."
110X=GET
120CLS
130PRINT:PRINT TAB(25,1) "COUNTER"
140J=0
150FOR N=1 TO 500
160IF J=20 THEN GOTO 300
170A%=(2^J)*((2^(J+1))-1)
180J=J+1
190X%=1
200M%=1
210M%=M%+1
220PRINT TAB(20,3) M%
230IF M%>A%/2+1 THEN GOTO 290
240IF X%>A% THEN GOTO 290
250B=A%/M%
260IF B=INT(B) THEN X%=X%+B ELSE GOTO
210
270IF B=2 THEN PRINT TAB(20,3) A% ELSE
GOTO 210
280IF X%=A% THEN PROCperfect
290NEXT
300END
310DEF PROCperfect
320Z=Z+1
330VDU2:IF Z=1 PRINT TAB(0,5+Z)"I'M A
PERFECT NUMBER ...",A%:VDU3
340VDU2:IF Z=2 PRINT TAB(0,5+Z)"...AND
SO AM I ...",A%:PRINT:VDU3
350VDU2:IF Z=2 PRINT TAB(0,7+Z)"PLEASE
WAIT.ANOTHER WILL BE ALONG SOON.":PRINT
:VDU3
360VDU2:IF Z=3 PRINT TAB(0,8+Z)"HERE I
AM ...",A%:PRINT:VDU3
370IF Z=3 THEN PROCtexta
380IF Z=4 THEN PROCtextb
390VDU2:IF Z>4 THEN PRINT "WAS IT WORT
H THE WAIT ...",A%:VDU3
400VDU3
410ENDPROC
420DEF PROCtexta
430VDU2:PRINT TAB(0,10+Z)"THERE'S NOT
MANY OF US AROUND YOU KNOW."
440PRINT "YOU'LL NOW HAVE A SLIGHT WAI
T BEFORE YOU SEE ANOTHER ONE(COUNTER=410
0 approx).":PRINT:VDU3
450ENDPROC
460DEF PROCtextb
470VDU2:PRINT TAB(0,12+Z)"NOT TOO LONG
A WAIT I HOPE ...",A%:PRINT
480PRINT "YOU'LL NOW HAVE A MUCH LONGE
R WAIT."
490PRINT "BE PREPARED TO LEAVE YOUR CO
MPUTER ON ALL WEEK OR POSSIBLY EVEN LO
NGER!":PRINT
500PRINT "THE NEXT PERFECT NUMBER IS M
UCH LARGER!!"
510ENDPROC