lcm

Least common multiple for 3 or more numbers

How do you calculate the least common multiple of multiple numbers? So far I've only been able to calculate it between two numbers. But have no idea how to expand it to calculate 3 or more numbers. So far this is how I did it LCM = num1 * num2 / gcd ( num1 , num2 ) With gcd is the function to calculate the greatest common divisor...

Finding the LCM of a range of numbers

I read an interesting DailyWTF post today, "Out of All The Possible Answers..." and it interested me enough to dig up the original forum post where it was submitted. This got me thinking how I would solve this interesting problem - the original question is posed on Project Euler as: 2520 is the smallest number that can be divided by...

How can I optimize my C / x86 code?

int lcm_old(int a, int b) { int n; for(n=1;;n++) if(n%a == 0 && n%b == 0) return n; } int lcm(int a,int b) { int n = 0; __asm { lstart: inc n; mov eax, n; mov edx, 0; idiv a; mov eax, 0; cmp eax, edx; jne lstart; mov eax, n; mo...

GCD function in matlab

hi, i am looking for a way to implement the "gcd" function used in matlab in another language but i really cant understand the way it functions. it says in http://www.mathworks.com/access/helpdesk/help/techdoc/ref/gcd.html that: "[G,C,D] = gcd(A,B) returns both the greatest common divisor array G, and the arrays C and D, which satisfy ...