Proper divisors: Difference between revisions

Content added Content deleted
(Added solution for Action!)
Line 198: Line 198:
=={{header|Action!}}==
=={{header|Action!}}==
Calculations on a real Atari 8-bit computer take quite long time. It is recommended to use an emulator capable with increasing speed of Atari CPU.
Calculations on a real Atari 8-bit computer take quite long time. It is recommended to use an emulator capable with increasing speed of Atari CPU.
<lang Action!>BYTE FUNC CountDivisors(INT a)
<lang Action!>BYTE FUNC GetDivisors(INT a INT ARRAY divisors)
INT i
BYTE prod,count

prod=1 count=0
WHILE a MOD 2=0
DO
count==+1
a==/2
OD
prod==*(1+count)

i=3
WHILE i*i<=a
DO
count=0
WHILE a MOD i=0
DO
count==+1
a==/i
OD
prod==*(1+count)
i==+2
OD

IF a>2 THEN
prod==*2
FI
RETURN (prod-1)

BYTE FUNC GetDivisors(INT a INT ARRAY divisors)
INT i,max
INT i,max
BYTE count
BYTE count
Line 244: Line 214:


PROC Main()
PROC Main()
DEFINE MAXNUM="20000"
INT i,j,count,max,ind,st,range
INT i,j,count,max,ind
INT ARRAY divisors(100)
INT ARRAY divisors(100)
BYTE perc
BYTE ARRAY pdc(MAXNUM+1)


FOR i=1 TO 10
FOR i=1 TO 10
Line 263: Line 234:


PutE() PrintE("Searching for max number of divisors:")
PutE() PrintE("Searching for max number of divisors:")

range=20000
FOR i=1 TO MAXNUM
max=0 ind=0 perc=0 st=range/100
DO
FOR i=1 TO range
pdc(i)=1
OD
FOR i=2 TO MAXNUM
DO
DO
IF i MOD st=0 THEN
FOR j=i+i TO MAXNUM STEP i
DO
PrintB(perc) Put('%) PutE() Put(28)
perc==+1
pdc(j)==+1
FI
OD
OD
count=CountDivisors(i)

max=0 ind=0
FOR i=1 TO MAXNUM
DO
count=pdc(i)
IF count>max THEN
IF count>max THEN
max=count ind=i
max=count ind=i