Greatest Common Divisor and Least Common Multiple More helpful functions not built into the calculator. I originally had much longer versions of these functions but I came upon shorter versions of GCD in the swissmicros forums and was moved. The shorter LCM is entirely mine. The new version uses some free42 extension functions, but they are optional: `FUNC 21` makes the function behave like a built-in binary function, dropping the stack and saving the original X into LASTX. They can be safely removed if this functionality isn't needed or if running on original hardware. (In addition, the `LBL 00` is only needed because FUNC can't be called multiple times in one function; if FUNC is removed we could remove the label and do `GTO "GCD"` instead.) `R^N 3` rotates only the bottom three registers. The equivalent in original hp42s functions is `Rv, X<>Y, R^, X<>Y`. Inputs: X, Y: integers Outputs: X: GCD(x, y) or LCM(x, y) 00 { 44-Byte Prgm } 01▸LBL "GCD" 02 FUNC 21 03▸LBL 00 04 MOD 05 LASTX 06 X<>Y 07 X!=0? 08 GTO 00 09 + 10 ABS 11 RTN 12▸LBL "LCM" 13 FUNC 21 14 RCL* ST Y 15 LASTX 16 R^N 3 17 XEQ "GCD" 18 / 19 ABS 20 END Here is my original version of the same function. GCD does unnecessary work: calling ABS on the inputs, ensuring Y > X before MOD, and overcomplicating the base case in a way that requires multiple labels. LCM duplicates both inputs and pushes them around the stack before doing the GCD and multiplication. I think I may have been unaware that recalling from stack registers was possible. 00 { 48-Byte Prgm } 01 LBL "GCD" 02 ABS 03 X<>Y 04 ABS 05 LBL 00 06 X>Y? 07 X<>Y 08 MOD 09 X=0? 10 GTO 01 11 LASTX 12 GTO 00 13 LBL 01 14 LASTX 15 RTN 16 LBL "LCM" 17 ENTER 18 ENTER 19 R^ 20 ENTER 21 Rv 22 * 23 ABS 24 ENTER 25 Rv 26 Rv 27 XEQ "GCD" 28 X<>Y 29 Rv 30 / 31 END