Anonymous user
Proper divisors: Difference between revisions
→{{header|REXX}}: added/changed whitespace and comments, moved the iSqrt function in-line, changed wording in the REXX section header.
m (→version 2: updated the output to reflect the highest number of Pdivs for 20k instead of 2k.) |
(→{{header|REXX}}: added/changed whitespace and comments, moved the iSqrt function in-line, changed wording in the REXX section header.) |
||
Line 1,644:
do i=1 for words(xtra); n=word(xtra,i)
numeric digits max(9,length(n)+1); q=Pdivs(n); #=words(q)
say right(n,max(20,
end /*i*/ /* [↑] support extra specified integers*/
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
Pdivs: procedure; parse arg x,b; x=abs(x); if x==1 then return ''
odd=x//2; if x==0 then return '∞'
a=1 /* [↓]
do j=2+odd by 1+odd while j*j<x /*divide by
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*/
/* [↓] adjust for a square.
if j*j==x then return a j b /*Was X a square?
return a b /*return the divisors (both lists). */</lang>
'''output''' when using the following input: <tt> 0 10 1 20000 166320 1441440 11796480000 </tt>
<pre>
0 has ∞ proper divisors: ∞
Line 1,679:
===version 3===
This REXX version is
It accomplishes a faster speed by incorporating the
<lang rexx>/*REXX program finds proper divisors (& count) of integer ranges; & max count.*/
parse arg bot top inc range xtra /*get optional arguments from CL.*/
Line 1,701 ⟶ 1,700:
do i=1 for words(xtra); n=word(xtra,i)
numeric digits max(9,length(n)+1); q=Pdivs(n); #=words(q)
say right(n,max(20,
end /*i*/ /* [↑] support extra specified integers*/
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
z=x; r=0; q=1; do while q<=z; q=q*4; end /*R will be the integer √ X */
▲a=1 /* [↓] do only EVEN or ODD #s. ___*/
▲ do j=2+odd by 1+odd while j<iqx /*divide by all the integers up to √ x */
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*/
/* [↓] adjust for a square.
if j*j==x then return a j b /*Was X a square?
return a b /*return the divisors (both lists). */</lang>
'''output''' is identical to the 2<sup>nd</sup> REXX version. <br><br>
|