Anonymous user
Factors of an integer: Difference between revisions
m
→optimized version: added/changed whitespace and comments.
(→{{header|Sidef}}: mentioned the built-in function) |
m (→optimized version: added/changed whitespace and comments.) |
||
Line 4,106:
<lang rexx>/*REXX program displays divisors of any [negative/zero/positive] integer or a range.*/
parse arg LO HI inc . /*obtain the optional args*/
HI= word(HI LO 20, 1); LO= word(LO 1,
w= length(
@.=left('',7);
say center('n', w) "#divisors" center('divisors', 60) /*display the header. */
say copies('═', w) "═════════" copies('═' , 60) /* " " separator. */
p#=0 /*count of prime numbers. */
do n=LO to HI by inc; divs=divisors(n); #=words(divs) /*get list of divs; # divs*/
if divs==$ then do; #=
p= @.#;
if p==@.2 then p#= p# +
say center(n, w) center('['#"]", 9) "──► " p ' ' divs
end /*n*/ /* [↑] process a range of integers. */
say
say
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
divisors: procedure; parse arg x 1 b; a=
if x<2 then do; x= abs(x); if x==1 then return 1; if x==0 then return '∞'; b=x; end
odd=x//2 /* [↓] process EVEN or ODD ints. ___*/
do j=2+odd by 1+odd while j*j<x /*divide by all the integers up to √ x */
Line 4,342:
200 [12] ──► 1 2 4 5 8 10 20 25 40 50 100 200
46 primes were found.
</pre>
|