-
Notifications
You must be signed in to change notification settings - Fork 989
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Java Solutions GCD of Factorials
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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 |
7ee6b8d
There was a problem hiding this comment.
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