Proper divisors: Difference between revisions

(Added solution for Action!)
Line 198:
=={{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.
<lang Action!>BYTE FUNC CountDivisorsGetDivisors(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
BYTE count
Line 244 ⟶ 214:
 
PROC Main()
DEFINE MAXNUM="20000"
INT i,j,count,max,ind,st,range
INT ARRAY divisors(100)
BYTE percARRAY pdc(MAXNUM+1)
 
FOR i=1 TO 10
Line 263 ⟶ 234:
 
PutE() PrintE("Searching for max number of divisors:")
 
range=20000
FOR i=1 TO rangeMAXNUM
max=0 ind=0 perc=0 st=range/100
DO
FOR i=1 TO range
countpdc(i)==+1
OD
FOR i=2 TO MAXNUM
DO
IFFOR j=i+i MODTO st=0MAXNUM THENSTEP i
a==/2DO
PrintB(perc) Put('%) PutE() Put(28)
percpdc(j)==+1
FIOD
OD
count=CountDivisors(i)
 
max=0 ind=0 perc=0 st=range/100
FOR i=1 TO MAXNUM
DO
prod=1 count=0pdc(i)
IF count>max THEN
max=count ind=i
Anonymous user