Talk:Least common multiple: Difference between revisions

From Rosetta Code
Content added Content deleted
Line 18: Line 18:


::Hi Rdm, try [http://rosettacode.org/mw/index.php?title=Least_common_multiple&oldid=104117 this direct link]. --[[User:Paddy3118|Paddy3118]] 13:35, 31 March 2011 (UTC)
::Hi Rdm, try [http://rosettacode.org/mw/index.php?title=Least_common_multiple&oldid=104117 this direct link]. --[[User:Paddy3118|Paddy3118]] 13:35, 31 March 2011 (UTC)

:Does lcm(x,y) = lcm(-x,y) = lcm(-x,-y)? If so then you could just change the sign on the arguments and use the fractional method. I'm pretty sure it works for positive numbers. The fractional method wouldn't work for fractional arguments, though (ex: lcm(1/3, 1/6) = 1/3 = 1 * 1/3 = 2 * 1/6). For those you would nee to use the "iteration over multiples" method I believe. --[[User:Mwn3d|Mwn3d]] 14:53, 31 March 2011 (UTC)

Revision as of 14:53, 31 March 2011

When I first wrote the task, I forgot about the special case for zero. I later added this special case to the task, but I left it as a draft task. --Kernigh 00:29, 31 March 2011 (UTC)

Yet another way, isn't?

From "Yet another way is to use rational arithmetic; if you add 1/m and 1/n and reduce the fraction, then the denominator is the lcm"

I did the following: <lang python>>>> def lcm(a, b): return (fractions.Fraction(1,a) + fractions.Fraction(1,b)).denominator if a and b else 0

>>> lcm(12, 18) 36 >>> lcm(-6, 14) 21 >>> # Whoops!</lang> It is out by any common factor. --Paddy3118 03:17, 31 March 2011 (UTC)

I do not know where you found that sentence, but a bigger problem seems to be that all of the page history for this page displays for me as 2011-03-11 when I believe this page has been around for quite some time. --Rdm 13:03, 31 March 2011 (UTC)
That sentence used to be in the description, but it was removed when it was found to be wrong. Also the page is even younger than that (as long as I'm reading your date format correctly) It was only created yesterday. I was amazed too. I thought for sure we had this one, but I couldn't find it. --Mwn3d 13:31, 31 March 2011 (UTC)
Hi Rdm, try this direct link. --Paddy3118 13:35, 31 March 2011 (UTC)
Does lcm(x,y) = lcm(-x,y) = lcm(-x,-y)? If so then you could just change the sign on the arguments and use the fractional method. I'm pretty sure it works for positive numbers. The fractional method wouldn't work for fractional arguments, though (ex: lcm(1/3, 1/6) = 1/3 = 1 * 1/3 = 2 * 1/6). For those you would nee to use the "iteration over multiples" method I believe. --Mwn3d 14:53, 31 March 2011 (UTC)