Count in factors: Difference between revisions

→‎{{header|REXX}}: optimized the 2nd REXX version.
m (→‎{{header|REXX}}: changed/added comments and whitespace, changed indentations.)
(→‎{{header|REXX}}: optimized the 2nd REXX version.)
Line 2,667:
===using integer SQRT===
This REXX version computes the   ''integer square root''   of the integer being factor   (to limit the range of factors),
<br>this makes this version slightlyabout 50% faster than the 1<sup>st</sup> REXX version.
 
Also, the number of early testing of prime factors was expanded.
 
Note that the &nbsp; '''integer square root''' &nbsp; section of code doesn't use any floating point numbers, just integers.
Line 2,688 ⟶ 2,690:
/*──────────────────────────────────────────────────────────────────────────────────────*/
factr: procedure; parse arg z 1 n,$; if z<2 then return z /*if Z too small, return Z*/
do while z// 2==0; $=$ 'x 2' ; z=z% 2; end /*maybe add factor of 2 */
do while z// 3==0; $=$ 'x 3' ; z=z% 3; end /* " " " " 3 */
do while z// 5==0; $=$ 'x 5' ; z=z% 5; end /* " " " " 5 */
do while z// 7==0; $=$ 'x 7' ; z=z% 7; end /* " " " " 7 */
t=do while z//11==0; r$=0$ 'x 11' ; qz=1z%11; end do while q<=t; q=q /*4; end" " /*R: " will be iSqrt" of 11 Z.*/
do while z//13==0; $=$ 'x 13' ; z=z%13; end /* " " " " 13 */
do while z//17==0; $=$ 'x 17' ; z=z%17; end /* " " " " 17 */
do while z//19==0; $=$ 'x 19' ; z=z%19; end /* " " " " 19 */
do while z//23==0; $=$ 'x 23' ; z=z%23; end /* " " " " 23 */
do while z//29==0; $=$ 'x 29' ; z=z%29; end /* " " " " 29 */
do while z//31==0; $=$ 'x 31' ; z=z%31; end /* " " " " 31 */
do while z//37==0; $=$ 'x 37' ; z=z%37; end /* " " " " 37 */
if z>40 then do
t=z; q=1; r=0; do while q<=t; q=q*4; end /*R: will be integer SQRT of Z.*/
 
do while q>1; q=q%4; _=t-r-q; r=r%2; if _>=0 then do; t=_; r=r+q; end
end /*while*/ /* [↑] compute thefind integer SQRT(z). of Z. */
 
do j=1141 by 6 to r while j<=z /*insure that J isn't divisible by 3.*/
parse var j '' -1 _ /*get the last decimal digit of J. */
if _\==5 then do while z//j==0; $=$ 'x' j; z=z%j; end /*maybe reduce Z.?*/
if _ ==3 then iterate /*if nextNext number will be ÷ by 5, ? skipSkip.*/
y=j+2
do while z//y==0; $=$ 'x' y; z=z%y; end /*maybe reduce Z.?*/
end /*j*/
end /*if z>40*/
 
if z==1 then z= /*if residual is unity, then nullify it*/