Proper divisors: Difference between revisions
Content added Content deleted
m (→version 3: changed wording in the REXX section header for version 3.) |
(→version 3: optimized the Pdivs function.) |
||
Line 1,679: | Line 1,679: | ||
===version 3=== |
===version 3=== |
||
This REXX version is |
This REXX version is over 12% faster than the REXX version 2 (more so when specifying larger numbers). |
||
It accomplishes a faster speed by incorporating the calculation of an ''integer square root'' of an integer (without using any floating point arithmetic). |
It accomplishes a faster speed by incorporating the calculation of an ''integer square root'' of an integer (without using any floating point arithmetic). |
||
Line 1,709: | Line 1,709: | ||
do while q>1; q=q%4; _=z-r-q; r=r%2; if _>=0 then do; z=_; r=r+q; end; end |
do while q>1; q=q%4; _=z-r-q; r=r%2; if _>=0 then do; z=_; r=r+q; end; end |
||
a=1 /* [↓] use all or only odd #s. ___ */ |
a=1 /* [↓] use all or only odd #s. ___ */ |
||
do j=2+odd by 1+odd |
do j=2+odd by 1+odd to r-(r*r==x) /*divide by some integers up to √ X */ |
||
if x//j==0 then do; a=a j; b=x%j b; end /*if ÷, add both divisors to α&ß*/ |
if x//j==0 then do; a=a j; b=x%j b; end /*if ÷, add both divisors to α&ß*/ |
||
end /*j*/ /* [↑] % is the REXX integer division*/ |
end /*j*/ /* [↑] % is the REXX integer division*/ |