Connection Status:
Competition Arena > FactorialGCD
SRM 283 · 2006-01-19 · by gevak · Math, Simple Search, Iteration
Class Name: FactorialGCD
Return Type: int
Method Name: factGCD
Arg Types: (int, int)
Problem Statement

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 int a and an int b as parameters and returns the GCD of a! (the factorial of a) and b.

Notes

  • Assume 0! = 1.

Constraints

  • a will be between 0 and 2147483647, inclusive.
  • b will be between 1 and 2147483647, inclusive.
Examples
0)
5
20
Returns: 20

5! = 120, so GCD(120,20) = 20.

1)
7
5040
Returns: 5040

7! = 5040, GCD(5040,5040) = 5040.

2)
0
2425
Returns: 1

Note that 0! = 1.

3)
667024
1
Returns: 1
4)
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.

Coding Area

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

Submitting as anonymous