TopCoder problem "FactorialGCD" used in SRM 283 (Division II Level Three)



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

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.
5)
    
2097711064
2147483646
Returns: 2147483646

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=5963

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=8080&pm=5963

Writer:

gevak

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Math, Simple Search, Iteration