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 |
<lang Action!>BYTE FUNC GetDivisors(INT a INT ARRAY divisors) |
||
INT i |
|||
BYTE prod,count |
|||
⚫ | |||
WHILE a MOD 2=0 |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
prod==*(1+count) |
|||
i=3 |
|||
WHILE i*i<=a |
|||
⚫ | |||
count=0 |
|||
WHILE a MOD i=0 |
|||
DO |
|||
count==+1 |
|||
a==/i |
|||
⚫ | |||
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 |
INT i,j,count,max,ind |
||
INT ARRAY divisors(100) |
INT ARRAY divisors(100) |
||
BYTE |
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=2 TO MAXNUM |
|||
DO |
DO |
||
FOR j=i+i TO MAXNUM STEP i |
|||
⚫ | |||
PrintB(perc) Put('%) PutE() Put(28) |
|||
pdc(j)==+1 |
|||
OD |
|||
⚫ | |||
count=CountDivisors(i) |
|||
⚫ | |||
FOR i=1 TO MAXNUM |
|||
⚫ | |||
⚫ | |||
IF count>max THEN |
IF count>max THEN |
||
max=count ind=i |
max=count ind=i |