#K40982. GCD of Powers with Factorials
GCD of Powers with Factorials
GCD of Powers with Factorials
Given two non-negative integers a and b, you are asked to compute the greatest common divisor (GCD) of a^(b!) and b^(a!). An interesting observation simplifies the problem substantially: it can be shown that
\(\gcd(a^{b!},\, b^{a!}) = \gcd(a, b)\)
with the special case that if both a and b are zero, the answer is defined to be 0. Therefore, your task reduces to computing \(\gcd(a, b)\) under this rule.
Note: The factorials in the exponents might look intimidating, but the mathematical property above allows a much simpler computation.
inputFormat
The input is read from standard input. It consists of two non-negative integers a and b separated by space.
outputFormat
Output the greatest common divisor of a and b to the standard output. In the special case when both a and b are 0, output 0.
## sample1 2
1