UIU: Competitive Programming: GCD & LCM



// @BEGIN_OF_SOURCE_CODE
 
#include <cstdio>
 
using namespace std;
 
int gcd(int a, int b)
{
    if ( a == 0 ) return b;
 
    return gcd(b % a, a);
}
 
int lcm(int a, int b)
{
    return (a * b) / gcd(a, b);
}
 
int main(int argc, const char * argv[])
{
    printf ("%d\n", gcd(42, 36));
 
    printf ("%d\n", gcd(36, 42));
 
    printf ("%d\n", lcm(36, 42));
 
    return 0;
}
 
// @END_OF_SOURCE_CODE


// TODO: using prime factor 

One thought on “UIU: Competitive Programming: GCD & LCM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s