Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Fast Greatest Common Divisor (GCD) Algorithm

, 18 Feb 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

Mauro Leggieri
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... PinmemberDrABELL18-Feb-11 9:48 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150301.1 | Last Updated 18 Feb 2011
Article Copyright 2011 by Mauro Leggieri
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid