A multifactorial of a number is a generalization of the factorial function. The k-multifactorial of n is denoted by fack(n). The k-multifactorial of n is the product of every positive number of the
form n - X*k, where X is a non-negative integer. For example, the 3-multifactorial of 14
is 14*11*8*5*2 = 12320, and the 4-multifactorial of 5 is 5*1 = 5.
A formal definition of multifactorial is:
- fack(n) = n if k >= n
- fack(n) = n*fack(n-k) if k < n
You will be given n and k and have to return the value of fack(n) as a String with no leading zeroes (this value is always a positive integer). If fack(n) is strictly greater than 1000000000000000000 (1018), return "overflow" (quotes for clarity) instead.
|