Anonymous user
Abundant odd numbers: Difference between revisions
→{{header|REXX}}: revised program to deal with new task requirements.
(→{{header|Go}}: Updated in line with revised task requirements.) |
(→{{header|REXX}}: revised program to deal with new task requirements.) |
||
Line 200:
=={{header|REXX}}==
<lang rexx>/*REXX pgm displays abundant
parse arg
if
numeric digits max(9, length(Novr) ) /*ensure enough decimal digits for // */
do j=1 until #>=N; $=sigma(j) /*get sigma for an integer. */▼
@= 'odd abundant number'
#= # + 1▼
if $<=j then iterate /*sigma ≤ J ? Then ignore it. */
#= # + 1 /*bump the counter for abundant odd #'s*/
say th(#) @ 'is: ' commas(j) right('sigma=',20) commas($)
say
# = 0 /*count of odd abundant numbers so far.*/
do j=5 by 10; $= sigO(j) /*get the sigma for an odd integer. */
if $<=j then iterate /*sigma ≤ J ? Then ignore it. */
#= # + 1 /*bump the counter for abundant odd #'s*/
if #<Nuno then iterate /*Odd abundant# count<Nuno? Then skip.*/
say th(#) @ 'is: ' commas(j) right('sigma=',20) commas($)
leave
end /*j*/
say
if $<=j then iterate /*sigma ≤ J ? Then ignore it. */
say th(1) @ 'over' commas(Novr) "is: " commas(j) right('sigma=',20) commas($)
leave
end /*j*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
th: parse arg th; return th||word('th st nd rd',1+(th//10)*(th//100%10\==1)*(th//10<4))
▲ s= 1 /* [↓] only use EVEN or ODD integers.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
sigO: procedure; parse arg x; s= 1
if x//k==0 then s= s + k +
if k*k==x then return s + k /*Was X a square? If so, add √ x */
return s /*return (sigma) sum of the divisors. */</lang>
{{out|output|text= when using the default input:}}
<pre>
1000th odd abundant number is: 498,225 sigma= 529,487
1st odd abundant number over 1,000,000,000 is: 1,000,000,575 sigma= 1,083,561,009
</pre>
|