Abundant odd numbers: Difference between revisions
→{{header|REXX}}: ooRexx conformance and only one loop instead of three
imported>Chinhouse No edit summary |
Walterpachl (talk | contribs) (→{{header|REXX}}: ooRexx conformance and only one loop instead of three) |
||
Line 5,833:
The '''sigO''' function is a specialized version of the '''sigma''' function optimized just for ''odd'' numbers.
<syntaxhighlight lang="rexx">/*REXX pgm displays abundant odd numbers: 1st 25,
parse arg Nlow Nuno Novr . /*obtain optional arguments from the CL*/
if Nlow=='' | Nlow==
if Nuno=='' | Nuno==
if Novr=='' | Novr==
numeric digits max(9,
d=sigO(j)
if $<=j then iterate /*sigma ≤ J ? Then ignore it. */▼
if d>j then Do
n= n
say rt(th(n)) a 'is:'rt(commas(j),8) rt('sigma=') rt(commas(d),9)
end /*j*/▼
End
say
d= sigO(j)
if $<=j then iterate /*sigma ≤ J ? Then ignore it. */▼
if d>j
n= n
say rt(th(n)) a 'is:'rt(commas(j),8) rt('sigma=') rt(commas(d),9)
leave /*we're finished displaying NUNOth num.*/
End
say
d= sigO(j)
if d>j
say rt(th(1)) a 'over' commas(Novr) 'is: ' commas(j) rt('sigma=') commas(d)
▲ end /*j*/
End
end /*j*/
exit
commas:parse arg _; do c_=length(_)-3 to 1 by -3; _=insert(',', _, c_); end; return _▼
/*--------------------------------------------------------------------------------------*/
rt: procedure; parse arg #,len; if len=='' then len= 20; return right(#, len)▼
th: parse arg th; return th||word('th st nd rd',1+(th//10)*(th//100%10\==1)*(th//10<4))▼
/*--------------------------------------------------------------------------------------*/
sigO: parse arg x;
s=1
do k=3 by 2
if x//k==0 then
return s /*return (sigma) sum of the divisors. */</syntaxhighlight>▼
s= s + k + x%k /*add the two divisors to (sigma) sum. */
if k*k==x then
return s + k /*Was X a square? If so,add v x */
</syntaxhighlight>
{{out|output|text= when using the default input:}}
<pre>
|