Skip to content

Commit

Permalink
Merge pull request #1901 from ujjwalhans/master
Browse files Browse the repository at this point in the history
gcd of two factorials
  • Loading branch information
vibrantachintya authored Oct 12, 2021
2 parents ce6e0ea + 8ebc122 commit 243afb7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
27 changes: 27 additions & 0 deletions C++/2021/9thOct_ujjwalhans.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <stdio.h>
int factorial(int n)
{
int f = 1;
int i;
for (i = 2; i <= n; i++)
f *= i;
return f;
}
int gcd(int a, int b)
{ if (a == 0)
return b;
if (b == 0)
return a;
if (a == b)
return a;
if (a > b)
return gcd(a-b, b);
return gcd(a, b-a);
}

int main()
{
int a = 5, b = 120;
printf("%d",factorial(gcd(a, b)));
return 0;
}
13 changes: 13 additions & 0 deletions Python/2021/9thOct_ujjwalhans.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import math
def gcd(a,b):
if (b == 0):
return a
if (a == 0):
return b
if (a == b):
return a
if (a > b):
return gcd(a-b, b)
return gcd(a, b-a)
ans=gcd(5,10)
print(math.factorial(ans))

0 comments on commit 243afb7

Please sign in to comment.