diff --git a/Mathematics/GCD/gcdlcm.py b/Mathematics/GCD/gcdlcm.py new file mode 100644 index 00000000..13f6e412 --- /dev/null +++ b/Mathematics/GCD/gcdlcm.py @@ -0,0 +1,14 @@ +def gcd(a,b): + if a == 0: + return b + return gcd(b % a, a) + +# Function to return LCM of two numbers +def lcm(a,b): + return (a / gcd(a,b))* b + +# Driver program to test above function +a = 15 +b = 20 +print('LCM of', a, 'and', b, 'is', lcm(a, b)) +print('GCD of', a, 'and', b, 'is', gcd(a, b)) diff --git a/Mathematics/GCD_LCM.cpp b/Mathematics/GCD_LCM.cpp new file mode 100644 index 00000000..3c0cd0b0 --- /dev/null +++ b/Mathematics/GCD_LCM.cpp @@ -0,0 +1,42 @@ + +#include +#include +using namespace std; +#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) +#define l long +#define ll long long +#define ull unsigned long long +#define ui unsigned int +#define vi vector +#define vll vector +#define pb push_back +#define ld long double +#define mp make_pair +#define pii pair +#define mod 1000000007 +#define rep(i,n) for(int i=0;i>a>>b; + cout <<"GCD of " << a << " and " + << b << " is " << gcd(a, b); + cout <<"LCM of " << a << " and " + << b << " is " << lcm(a, b); + return 0; +}