Last active
August 29, 2015 14:08
-
-
Save tanitanin/a9fbfa3c6051eaeb35e7 to your computer and use it in GitHub Desktop.
GCD & LCM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
template<class T> T gcd(T a, T b) { | |
T c; | |
while ( a != 0 ) { c = a; a = b%a; b = c; } | |
return b; | |
} | |
template<class T> T lcm(T a, T b) { | |
return a / gcd(a,b) * b; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment