Post Reply 
Find LCM of 2 numbers without using GCD
07-30-2018, 04:07 PM
Post: #3
RE: Find LCM of 2 numbers without using GCD
This is the Python program that I came up with:
Code:
def lcm(a, b):
    p, q = a, b
    while p != q:
        if p < q:
            p += a
        else:
            q += b
    return p

And this is for the HP-42S:
Code:
00 { 30 Byte-Prgm }
01 LBL "LCM"
02 RCL ST Y
03 RCL ST Y
04 LBL 00
05 X=Y?
06 RTN
07 X<Y?
08 GTO 01
09 X<>Y
10 RCL+ ST T
11 X<>Y
12 GTO 00
13 LBL 01
14 RCL+ ST Z
15 GTO 00
16 END

I hope that's what you had in mind.

Cheers
Thomas

PS: Look ma, no modulus.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Find LCM of 2 numbers without using GCD - Thomas Klemm - 07-30-2018 04:07 PM



User(s) browsing this thread: 1 Guest(s)