59 lines
921 B
Text
59 lines
921 B
Text
BYTE FUNC GetDivisors(INT a INT ARRAY divisors)
|
|
INT i,max
|
|
BYTE count
|
|
|
|
max=a/2
|
|
count=0
|
|
FOR i=1 TO max
|
|
DO
|
|
IF a MOD i=0 THEN
|
|
divisors(count)=i
|
|
count==+1
|
|
FI
|
|
OD
|
|
RETURN (count)
|
|
|
|
PROC Main()
|
|
DEFINE MAXNUM="20000"
|
|
INT i,j,count,max,ind
|
|
INT ARRAY divisors(100)
|
|
BYTE ARRAY pdc(MAXNUM+1)
|
|
|
|
FOR i=1 TO 10
|
|
DO
|
|
count=GetDivisors(i,divisors)
|
|
PrintF("%I has %I proper divisors: [",i,count)
|
|
FOR j=0 TO count-1
|
|
DO
|
|
PrintI(divisors(j))
|
|
IF j<count-1 THEN
|
|
Put(32)
|
|
FI
|
|
OD
|
|
PrintE("]")
|
|
OD
|
|
|
|
PutE() PrintE("Searching for max number of divisors:")
|
|
|
|
FOR i=1 TO MAXNUM
|
|
DO
|
|
pdc(i)=1
|
|
OD
|
|
FOR i=2 TO MAXNUM
|
|
DO
|
|
FOR j=i+i TO MAXNUM STEP i
|
|
DO
|
|
pdc(j)==+1
|
|
OD
|
|
OD
|
|
|
|
max=0 ind=0
|
|
FOR i=1 TO MAXNUM
|
|
DO
|
|
count=pdc(i)
|
|
IF count>max THEN
|
|
max=count ind=i
|
|
FI
|
|
OD
|
|
PrintF("%I has %I proper divisors%E",ind,max)
|
|
RETURN
|