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 N niceodd numbers,: where nice1st #'s25, are whoseone─thousandth, sum offirst its> factors1 > #billion. */
parse arg N . Nlow Nuno Novr . /*obtain optional arguments from the CL*/
if NNlow=='' | NNlow=="," then NNlow= 25 25 /*Not specified? Then use the default.*/
wif Nuno=='' length(N);| Nuno=="," then Nuno= 1000 /* " ww= w+ w " /*used" " " for" aligning the columnar output*/
#if Novr=='' 0| Novr=="," then Novr= 1000000000 /* " " " " " /*count of nice numbers (so far). " */
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' if $<=j then iterate /*sigmavariable for +annotating the J ? Then ignore itoutput. */
# = 0 s= 1 /*count [↓] only useof odd EVENabundant ornumbers ODDso integersfar.*/
#= # + 1
saydo 'nicej=5 number 'by 10 right(until #,w)>=Nlow; $= " is:" rightsigO(j,ww)', /*get the sigma is:' for right($,ww)an odd integer. */
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($)
#=end # + 1/*j*/
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
do j=15+Novr%5*5 untilby #>=N10; $=sigma sigO(j) /*get sigma for an odd integer. > Novr. */
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. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
sigmacommas: procedure; parse arg x_; if x<2do c_=length(_)-3 then returnto 0;1 odd=by x-3; //_=insert(',', 2_, c_); /*end; // ◄──remainder.*/return _
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.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
do j=2+odd by 1+odd while j*j<x /*divide by all integers up to √x. */
sigO: procedure; parse arg x; s= 1 if x//j==0 then s= s + j/*sigma +for odd integers. x%j /*add the two divisors to (sigma) sum. ___*/
end /*j*/ do k=3 by 2 while k*k<x /*divide [↑]by all %odd integers isup theto REXX integerx division*/
if x//k==0 then s= s + k + x%k /*add [↓]the two adjustdivisors forto a(sigma) squaresum. ___ */
if j end /*j==xk*/ then return s + j /*Was X a square? If so, add x ___*/
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=&nbsp; when using the default input:}}
<pre>
nice1st odd abundant number is: 1945 is: 12, sigma is: 16 sigma= 975
nice2nd odd abundant number is: 21,575 is: 18, sigma is: 21 sigma= 1,649
nice3rd odd abundant number is: 32,205 is: 20, sigma is: 22 sigma= 2,241
nice4th odd abundant number is: 42,835 is: 24, sigma is: 36 sigma= 2,973
nice5th odd abundant number is: 53,465 is: 30, sigma is: 42 sigma= 4,023
nice6th odd abundant number is: 64,095 is: 36, sigma is: 55 sigma= 4,641
nice7th odd abundant number is: 74,725 is: 40, sigma is: 50 sigma= 5,195
nice8th odd abundant number is: 85,355 is: 42, sigma is: 54 sigma= 5,877
nice9th odd abundant number is: 95,775 is: 48, sigma is: 76 sigma= 6,129
nice10th numberodd abundant 10 number is: 545,985 sigma is: 66 sigma= 6,495
nice11th numberodd abundant 11 number is: 566,435 sigma is: 64 sigma= 6,669
nice12th numberodd abundant 12 number is: 606,615 sigma is: 108 sigma= 7,065
nice13th numberodd abundant 13 number is: 666,825 sigma is: 78 sigma= 7,063
nice14th numberodd abundant 14 number is: 707,245 sigma is: 74 sigma= 7,731
nice15th numberodd abundant 15 number is: 727,425 sigma is: 123 sigma= 7,455
nice16th numberodd abundant 16 number is: 787,875 sigma is: 90 sigma= 8,349
nice17th numberodd abundant 17 number is: 808,085 sigma is: 106 sigma= 8,331
nice18th numberodd abundant 18 number is: 848,415 sigma is: 140 sigma= 8,433
nice19th numberodd abundant 19 number is: 888,505 sigma is: 92 sigma= 8,967
nice20th numberodd abundant 20 number is: 908,925 sigma is: 144 sigma= 8,931
nice21st numberodd abundant 21 number is: 969,135 sigma is: 156 sigma= 9,585
nice22nd numberodd abundant 22 number is: 1009,555 sigma is: 117 sigma= 9,597
nice23rd numberodd abundant 23 number is: 1029,765 sigma is: 114 sigma= 10,203
nice24th numberodd abundant 24 number is: 10410,395 sigma is: 106 sigma= 12,645
nice25th numberodd abundant 25 number is: 10811,025 sigma is: 172 sigma= 11,946
 
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>