algorithm to prove lcm:(adsbygoogle = window.adsbygoogle || []).push({});

a:=m

b:=n

while a != b

if a < b

a:= a + m

else

b:= b + n

//postcondition: a is the lcm(m,n)

what's the loop invariant?I thought it is(not sure):

lcm(ak, bk) = lcm(ak/m, bk/n) *lcm(m,n)

I am not sure and also impossible to prove my loop invariant....

Another loop invariant I thought is "ak=qm and bk=rn",but I don't know how to

show it's the lcm of m and n,

Thanks in advance!!

**Physics Forums - The Fusion of Science and Community**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Prove the algorithm for LCM

Loading...

Similar Threads for Prove algorithm | Date |
---|---|

I Prove if x + (1/x) = 1 then x^7 + (1/x^7) = 1. | Mar 9, 2016 |

I Proving Odd and Even | Feb 13, 2016 |

Prove A.(B+C) = (A.B)+(A.C) <Boolean Algebra> | Oct 24, 2015 |

Proving termination and correctness of the algorithm | Jul 14, 2013 |

**Physics Forums - The Fusion of Science and Community**