Post Reply 
Find LCM of 2 numbers without using GCD
07-30-2018, 06:22 PM (This post was last modified: 07-30-2018 06:24 PM by Dieter.)
Post: #9
RE: Find LCM of 2 numbers without using GCD
(07-30-2018 04:07 PM)Thomas Klemm Wrote:  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
...
I hope that's what you had in mind.

I think that's a different algorithm. ;-)

On the 12C it would translate into something like this:

Code:
01 STO 2
02 X<>Y
03 STO 1
04 -
05 X=0?
06 GTO 20
07 LstX
08 +
09 LstX
10 X<=Y?
11 GTO 17
12 X<>Y
13 RCL 2
14 +
15 X<>Y
16 GTO 04
17 RCL 1
18 +
19 GTO 04
20 LstX  
21 GTO 00

35 [ENTER] 50 [R/S] => 350

Dieter
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 - Dieter - 07-30-2018 06:22 PM



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