Jump to content

Count in factors: Difference between revisions

m
→‎using integer SQRT: added/changed some comments, optimized the function.
m (→‎{{header|REXX}}: optimized the function, simplified some code, added/changed whitespace and comments.)
m (→‎using integer SQRT: added/changed some comments, optimized the function.)
Line 3,340:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
factr: procedure; parse arg z 1 n,$; if z<2 then return z /*if Z too small, return Z*/
do while z// 2==0; $= $'x2' ; z= z%2 ; end /*maybe add factor of 2 */
do while z// 3==0; $= $'x3' ; z= z%3 ; end /* " " " " 3 */
Line 3,353:
do while z//31==0; $= $'x31'; z= z%31; end /* " " " " 31 */
do while z//37==0; $= $'x37'; z= z%37; end /* " " " " 37 */
r= 0 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.while*/
if z>40 then do; t= z; q= 1; do while q<=t>1; q=q%4; _=t-r-q; * 4r=r%2; if _>=0 endthen do; /*while*/t=_; r=r+q
do while q>1; q= q%4; _= t-r-q; r= r%2; if _>=0 then do; t=_; r=r+q end
end
end /*while*/ /* [↑] find integer SQRT(z). */
/*R: is the integer SQRT of endZ.*/
 
do j=41 by 6 to r while j<=z /*insure J isn't divisible by 3*/
parse var j '' -1 _ /*get last decimal digit of J.*/
Cookies help us deliver our services. By using our services, you agree to our use of cookies.