Multifactorial
Easy
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
The k-multifactorial of n is denoted by fac[k]
(n) and is defined as the product of every positive number of the form n – k * x, x = 0, 1, 2, … .
A formal definition of multifactorial is:
fac[k]
(n) = n, if k ≥ n;
fac[k]
(n) = n * fac[k]
(n – k), if k < n;
You will be given n and k and have to evaluate the value of fac[k]
(n). If the result is strictly greater than 10^18
, you must print "overflow".
Input
Two integers n and k (1 ≤ n, k ≤ 2 * 10^9
).
Output
Print the value of fac[k]
(n). If it is strictly greater than 10^18
, print "overflow".
Examples
Input #1
Answer #1
Input #2
Answer #2
Submissions 6K
Acceptance rate 16%