Proper divisors: Difference between revisions
Content deleted Content added
m →version 2: moved some statements. |
m →version 3: re-arranged some statements for better reading. |
||
Line 3,724: | Line 3,724: | ||
say right(n, max(20, w) ) 'has' center(#, 4) "proper divisors: " q |
say right(n, max(20, w) ) 'has' center(#, 4) "proper divisors: " q |
||
end /*n*/ |
end /*n*/ |
||
say /* [↑] process 1st range of integers.*/ |
|||
m=0 /*M ≡ maximum number of Pdivs (so far).*/ |
m=0 /*M ≡ maximum number of Pdivs (so far).*/ |
||
do r=1 for range |
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.*/ |
|||
if #<m then iterate /*Less then max? Then ignore this #. */ |
if #<m then iterate /*Less then max? Then ignore this #. */ |
||
@.#= @.# @. r; |
@.#= @.# @. r; m=# /*add this Pdiv to max list; set new M.*/ |
||
end /*r*/ /* [↑] process 2nd range of integers.*/ |
end /*r*/ /* [↑] process 2nd range of integers.*/ |
||
say |
|||
say m ' is the highest number of proper divisors in range 1──►'range, |
say m ' is the highest number of proper divisors in range 1──►'range, |
||
", and it's for: " subword(@.m, 3) |
", and it's for: " subword(@.m, 3) |
||
Line 3,745: | Line 3,744: | ||
Pdivs: procedure; parse arg x 1 z,b; x= abs(x); if x==1 then return '' /*unity?*/ |
Pdivs: procedure; parse arg x 1 z,b; x= abs(x); if x==1 then return '' /*unity?*/ |
||
odd= x // 2; if x==0 then return '∞' /*zero ?*/ |
odd= x // 2; if x==0 then return '∞' /*zero ?*/ |
||
r= 0 |
r= 0; q= 1 /* [↓] ══integer square root══ ___ */ |
||
do while q<=z; q=q*4; end /*R: an integer which will be √ X */ |
|||
do while q>1; q=q%4; _= z-r-q; r=r%2; if _>=0 then do; z=_; r=r+q; end |
|||
end /*while q>1*/ /* [↑] compute the integer sqrt of X.*/ |
|||
a=1 /* [↓] use all, or only odd #s. ___ */ |
a=1 /* [↓] use all, or only odd #s. ___ */ |
||
do j=2 +odd by 1 +odd to r -(r*r==x) /*divide by some integers up to √ X */ |
do j=2 +odd by 1 +odd to r -(r*r==x) /*divide by some integers up to √ X */ |