Jump to content

Proper divisors: Difference between revisions

m
→‎{{header|REXX}}: added comments and whitespace.
(→‎{{header|ALGOL 68}}: Added alternative, faster proper divisor counting example.)
m (→‎{{header|REXX}}: added comments and whitespace.)
Line 4,934:
=={{header|REXX}}==
===version 1===
<lang rexx>Call time 'R'
/*REXX*/
 
Call time 'R'
Do x=1 To 10
Say x '->' proper_divisors(x)
Line 5,020 ⟶ 5,023:
say right(n, max(20, w) ) 'has' center(#, 4) "proper divisors: " q
end /*n*/
m=0 0 /*M ≡ maximum number of Pdivs (so far).*/
do r=1 for range; q= Pdivs(r) /*process the second range specified. */
#= words(q); if #<m then iterate /*get proper divs; get number of Pdivs.*/
Line 5,036 ⟶ 5,039:
say right(n, max(20, w) ) 'has' center(#, 4) "proper divisors."
end /*i*/ /* [↑] support extra specified integers*/
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Pdivs: procedure; parse arg x,b; x= abs(x); if x==1 then return '' /*unity?*/
Line 5,092 ⟶ 5,095:
say right(n, max(20, w) ) 'has' center(#, 4) "proper divisors: " q
end /*n*/
m=0 0 /*M ≡ maximum number of Pdivs (so far).*/
do r=1 for range; q= Pdivs(r) /*process the second range specified. */
#= words(q); if #<m then iterate /*get proper divs; get number of Pdivs.*/
Line 5,108 ⟶ 5,111:
say right(n, max(20, w) ) 'has' center(#, 4) "proper divisors."
end /*i*/ /* [↑] support extra specified integers*/
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Pdivs: procedure; parse arg x 1 z,b; x= abs(x); if x==1 then return '' /*unity?*/
Line 5,144 ⟶ 5,147:
say right(n, max(20, w) ) 'has' center(#, 4) "proper divisors: " q
end /*n*/
m=0 0 /*M ≡ maximum number of Pdivs (so far).*/
do r=1 for range; q= Pdivs(r) /*process the second range specified. */
#= words(q); if #<m then iterate /*get proper divs; get number of Pdivs.*/
Line 5,160 ⟶ 5,163:
say right(n, max(20, w) ) 'has' center(#, 4) "proper divisors."
end /*i*/ /* [↑] support extra specified integers*/
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
iSqrt: procedure; parse arg x; r=0; q=1; do while q<=x; q=q*4; end
Cookies help us deliver our services. By using our services, you agree to our use of cookies.