FactorialGCD
SRM 283 · 2006-01-19 · by gevak
Problem Statement
The greatest common divisor (GCD) of two positive integers a and b is the largest integer that evenly divides both a and b. In this problem, you will find the GCD of a positive integer and the factorial of a non-negative integer.
Create a class FactorialGCD with method factGCD which takes an
Notes
- Assume 0! = 1.
Constraints
- a will be between 0 and 2147483647, inclusive.
- b will be between 1 and 2147483647, inclusive.
5 20 Returns: 20
5! = 120, so GCD(120,20) = 20.
7 5040 Returns: 5040
7! = 5040, GCD(5040,5040) = 5040.
0 2425 Returns: 1
Note that 0! = 1.
667024 1 Returns: 1
4 40 Returns: 8
4! = 24, so GCD(24,40) = 8.
Submissions are judged against all 170 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class FactorialGCD with a public method int factGCD(int a, int b) · 170 test cases · 2 s / 256 MB per case