Multifactorial
The k-multifactorial of n is denoted by fack(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:
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 evaluate the value of fack(n). If the result is strictly greater than 1018, you must print "overflow".
Specifications
Input
Two integers n and k (1 ≤ n, k ≤ 2 * 109).
Output
The value of fack(n). If it is strictly greater than 1018, print "overflow".
Problem information
Time Limit: 1 secondsMemory Limit: 64 MB
Balls for the passed test: 5
Complexity: 35% 51/78
Classes: Simple mathematics
Example
Example inputSample 1 14 3 Sample 2 1000 2 |
Example outputSample 1 12320 Sample 2 overflow |
| ← MassiveNumbers | Problems | Rock, Paper, or Scissors? → |
