Skip to content

Commit

Permalink
Create 9thOct_RitikD.java
Browse files Browse the repository at this point in the history
Java Solutions GCD of Factorials
  • Loading branch information
RitikD authored Oct 21, 2021
1 parent 5f4f454 commit 7ee6b8d
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions JAVA/2021/9thOct_RitikD.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Java program to find GCD of factorial
// of two numbers.
public class FactorialGCD{

static int factorial(int x)
{
if (x <= 1)
return 1;
int res = 2;
for (int i = 3; i <= x; i++)
res = res * i;
return res;
}

static int gcdOfFactorial(int m, int n)
{
int min = m < n ? m : n;
return factorial(min);
}

/* Driver program to test above functions */
public static void main (String[] args)
{
int m = 5, n = 120;

System.out.println(gcdOfFactorial(m, n));
}
}

//Output
//120

1 comment on commit 7ee6b8d

@RitikD
Copy link
Author

@RitikD RitikD commented on 7ee6b8d Oct 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #1875
GCD of Factorials problem solution is submitted in Java @vibrantachintya

Please sign in to comment.