Anonymous user
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
Also, the number of early testing of prime factors was expanded.
Note that the '''integer square root''' 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
do while z// 3==0; $=$ 'x 3' ; z=z% 3; end
do while z// 5==0; $=$ 'x 5' ; z=z% 5; end
do while z// 7==0; $=$ 'x 7' ; z=z% 7; end
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;
end /*while*/ /* [↑]
do j=
parse var j '' -1 _
if _\==5 then do while z//j==0;
if _ ==3 then iterate
y=j+2
do while z//y==0;
end /*j*/
end /*if z>40*/
if z==1 then z= /*if residual is unity, then nullify it*/
|