Anonymous user
Count in factors: Difference between revisions
m
→{{header|REXX}}: added/changed whitespace and comments, optimized a part of primality testing.
No edit summary |
m (→{{header|REXX}}: added/changed whitespace and comments, optimized a part of primality testing.) |
||
Line 2,365:
It couldn't be determined if the '''x''' (for multiplication) was a strict requirement or
<br>whether there're blanks surrounding the '''x''' (blanks were assumed for this example for readability).
<br>
<br><br>Also, as per the task's requirements, the prime factors of '''1''' (unity) will be listed as '''1''',▼
'''blanks=0''' will remove all blanks around the '''x'''.
▲
<br>even though, strictly speaking, it should be '''null'''. The same applies to '''0'''.
<br>prime factors are listed, but the number of primes found is always shown. The showing of the count of
<br>primes was included to help verify the factoring (of
<lang rexx>/*REXX program lists the prime factors of a specified integer (or a range).*/
@.=left('',8);
parse arg low high . /*get
if low=='' then do;low=1;high=40;end /*No LOW & HIGH? Then use the default.*/
if high=='' then high=low; oHigh=high /*No HIGH?
w=length(high); high=abs(high) /*get
numeric digits max(9,w+1) /*maybe bump the precision of numbers. */
blanks=1 /*1
if p==1 then #=
say right(n,w)
▲ end /*n*/ /*if BLANKS=0, no spaces around X*/
say
say right(
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
factr: procedure
do y=0 by 2; j=j+2+y//4 /*insure it's not divisible by three. */
if
if
▲ end /*y*/
if z==1 then z= /*if residual is
return strip(strip(
/*────────────────────────────────────────────────────────────────────────────*/
.
▲'''output''' when using the default for inputs:
<pre style="height:40ex">
1 = {unity} 1
Line 2,459 ⟶ 2,458:
12 primes found.
</pre>
'''output''' when the following input was used: <tt> 1 -10000 </tt>
<pre>
1229 primes found.
|