Re: lcm program on hp 33s Message #4 Posted by Katie Wasserman on 12 Dec 2005, 10:21 a.m., in response to message #1 by kevin
Here are LCM and GCD routines for the 32SII/33S that I came up with. Note that LCM(m,n)= m x n / GCD(m,n) and LCM is computed here using Euclid's method. It's really fast, worst case is on the order of log base 2 of the smaller of m, n.
LCM: call with m,n in x,y return with LCM in x
uses: A, B, x,y,z,t
L01 LBL L
L02 STO A
L03 x<>y
L04 STOx A
L05 XEQ G
L06 RCL A
L07 x<>y
L08 /
L09 RTN
GCD: call with m,n in x,y return with GCD in x
uses: B, x,y,z,t
G01 LBL G
G02 x>y?
G03 x<>y
G04 STO B
G05 0  these 7 instructions are just
G06 ENTER  to compute y mod x. On a 33S
G07 CMPLX+  You can replace these with
G08 /  the single instruction:
G09 IP  RMDR
G10 x 
G11  
G12 RCL B
G13 x<>y
G14 x>0?
G15 GTO G
G16 RCL B
G17 RTN
