TopcoderArchive
SRM19 Jan 2006
SRM 283

FactorialGCD

Problem statement, definition, constraints, and public examples.

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.

Definition

Class:
FactorialGCD
Method:
factGCD
Parameters:
int, int
Returns:
int
Method signature:
int factGCD(int a, int b)
(be sure your method is public)

Notes

  • Assume 0! = 1.

Constraints

  • a will be between 0 and 2147483647, inclusive.
  • b will be between 1 and 2147483647, inclusive.

Examples

  1. 5
    20
    Returns: 20
    5! = 120, so GCD(120,20) = 20.
  2. 7
    5040
    Returns: 5040
    7! = 5040, GCD(5040,5040) = 5040.
  3. 0
    2425
    Returns: 1
    Note that 0! = 1.
  4. 667024
    1
    Returns: 1
  5. 4
    40
    Returns: 8
    4! = 24, so GCD(24,40) = 8.
  6. 2097711064
    2147483646
    Returns: 2147483646
Back to all problems