Click here to Skip to main content
15,885,767 members
Articles / General Programming / Algorithms
Alternative
Tip/Trick

Fast Greatest Common Divisor (GCD) Algorithm

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
18 Feb 2011CPOL 8.4K   1   1
It is better to do this:public static long LCM(long a, long b){ return (a / GCD(a,b)) * b;}To avoid overflow on big numbers.
It is better to do this:

public static long LCM(long a, long b)
{
    return (a / GCD(a,b)) * b;
}


To avoid overflow on big numbers.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Argentina Argentina
My name is Mauro Leggieri. I am 30 year-old, married and have a child.

I am a system engineer (UTN university) and am being programming for more than 20 years from the C64 to the PC and some microcontrollers.

Mostly of my time, I program games for Windows.

Soon, my site http://www.mauroleggieri.com.ar

Comments and Discussions

 
GeneralHi Mauro, You are absolutely right; that's exactly how it's... Pin
DrABELL18-Feb-11 8:48
DrABELL18-Feb-11 8:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.