Skip to content

Instantly share code, notes, and snippets.

@tanitanin
Last active August 29, 2015 14:08
Show Gist options
  • Save tanitanin/a9fbfa3c6051eaeb35e7 to your computer and use it in GitHub Desktop.
Save tanitanin/a9fbfa3c6051eaeb35e7 to your computer and use it in GitHub Desktop.
GCD & LCM
#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