Aliquot sequence classifications: Difference between revisions

m
→‎{{header|REXX}}: changed an array name, changed a comment.
m (→‎{{header|REXX}}: ussed the uppercase version of a REXX variable.)
m (→‎{{header|REXX}}: changed an array name, changed a comment.)
Line 594:
big=2**47; NTlimit=16+1 /*limit: non-terminating*/
numeric digits max(9, 1+length(big)) /*be able to handle // */
@#.=.; @#.0=0; @#.1=0 /*proper divisor sums. */
say center('numbers from ' low " to " high, 79, "═")
 
Line 617:
/*──────────────────────────────────CLASSIFY_ALIQUOT subroutine─────────*/
classify_aliquot: parse arg a 1 aa; a=abs(a) /*get what # to be used.*/
if @#.a\==. then s=@#.a /*Was number been summed before? */
else s=SPdivssigma(a) /*No, then do it the hard way. */
@#.a=s; $=s /*define sum of the proper DIVs. */
what='terminating' /*assume this classification kind*/
c.=0; c.s=1 /*clear all cyclic seqs, set 1st.*/
Line 625:
else do t=1 while s\==0 /*loop until sum isn't 0 or >big.*/
m=word($, words($)) /*obtain the last number in seq. */
if @#.m==. then s=SPdivssigma(m) /*if ¬defined, then sum Pdivs.*/
else s=@#.m /*use the previously found number*/
if m==s & m\==0 then do; what='aspiring' ; leave; end
if word($,2)==a then do; what='amicable' ; leave; end
Line 641:
/*──────────────────────────────────SHOW_CLASS subroutine───────────────*/
show_class: say right(arg(1),digits()) 'is' center(what,15) arg(2); return
/*──────────────────────────────────SIGMA subroutine────────────────────*/
/*──────────────────────────────────SPDIVS subroutine───────────────────*/
SPdivssigma: procedure expose @#.; parse arg x; if x<2 then return 0; odd=x//2
s=1 /* [↓] use only EVEN|ODD integers*/
do j=2+odd by 1+odd while j*j<x /*divide by all integers up to √x*/
Line 649:
/* [↓] adjust for square. _ */
if j*j==x then s=s+j /*Was X a square? If so, add √x.*/
@#.x=s /*define the sum for the arg X. */
return s /*return divisorsthe sum (bothof lists).the divisors.*/</lang>
'''output''' &nbsp; when using the default input:
<pre>