Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!adm!crobbins@Cs.Ucl.AC.UK From: crobbins@Cs.Ucl.AC.UK (Colin J Robbins) Newsgroups: comp.lang.pascal Subject: Perfect number program Message-ID: <9657@brl-adm.ARPA> Date: Wed, 7-Oct-87 05:19:03 EDT Article-I.D.: brl-adm.9657 Posted: Wed Oct 7 05:19:03 1987 Date-Received: Sat, 10-Oct-87 07:37:53 EDT Sender: news@brl-adm.ARPA Lines: 25 For a start you could remove 2 of the divides in the inner loop like thus: FOR I=2 TO 10000 DO BEGIN W = 0; D = I/K; FOR K=2 TO I DO IF D = TRUNC (D) THEN W=W+(D) IF W=I THEN PRINT W "IS A PERFECT NUMBER" END This should have approximately a 3 fold increse in speed. Secondly, you could write a more inteligent routin altogether that take account of the factors tried before, for example, if 2 was not a factor then it is pointless trying 4,6,8 etc to see if the are factors. The routine for this - left as an exercise for the reader !!! Colin Robbins University College, London England.