Post Reply 
Find LCM of 2 numbers without using GCD
07-30-2018, 06:02 PM
Post: #6
RE: Find LCM of 2 numbers without using GCD
(07-30-2018 01:06 PM)Gamo Wrote:  Found this topic interesting and would like to share the concept on how to find the LCM without first calculating the GCD.

The approach is to start with the largest of the 2 numbers and keep incrementing the larger number by itself till smaller number perfectly divides the resultant.
...
The problem is I'm still figuring out on how to program this algorithm by using RPN programmable calculator.

I assume you're especially interested in a version for the 12C, so here it is:

Code:
01 X<=Y?
02 X<>Y
03 X<>Y
04 STO 0
05 X<>Y
06 ENTER
07 ENTER
08 ENTER
09 RCL 0
10 /
11 FRAC
12 X=0?
13 GTO 17
14 Rv
15 +
16 GTO 07
17 +
18 GTO 00

The larger number is kept on the stack, the smaller one is in R0.

15 [ENTER] 20 [R/S] => 60

Additional feature: replace the last line with these ones....

Code:
18 X<>Y
19 RCL 0
20 x
21 X<>Y
22 /
23 LstX
24 GTO 00

... and you get both the LCM (in X) and the GCD (in Y).

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:02 PM



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