Count in factors: Difference between revisions
Content added Content deleted
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: | Line 3,340: | ||
exit /*stick a fork in it, we're all done. */ |
exit /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
factr: procedure; parse arg z 1 n,$; if z<2 then return z |
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// 2==0; $= $'x2' ; z= z%2 ; end /*maybe add factor of 2 */ |
||
do while z// 3==0; $= $'x3' ; z= z%3 ; end /* " " " " 3 */ |
do while z// 3==0; $= $'x3' ; z= z%3 ; end /* " " " " 3 */ |
||
Line 3,353: | Line 3,353: | ||
do while z//31==0; $= $'x31'; z= z%31; end /* " " " " 31 */ |
do while z//31==0; $= $'x31'; z= z%31; end /* " " " " 31 */ |
||
do while z//37==0; $= $'x37'; z= z%37; end /* " " " " 37 */ |
do while z//37==0; $= $'x37'; z= z%37; end /* " " " " 37 */ |
||
if z>40 then do; t=z; q=1; r=0; do while q<=t; q= q * 4; end /*while*/ |
|||
do while q>1; q=q%4; _=t-r-q; r=r%2; if _>=0 then do; t=_; r=r+q |
|||
end |
|||
⚫ | |||
end /*while*/ /* [↑] find integer SQRT(z). */ |
end /*while*/ /* [↑] find integer SQRT(z). */ |
||
⚫ | |||
do j=41 by 6 to r while j<=z /*insure J isn't divisible by 3*/ |
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.*/ |
parse var j '' -1 _ /*get last decimal digit of J.*/ |