#P9134. When Can a Module be Completed?
When Can a Module be Completed?
When Can a Module be Completed?
Little E needs to install \(n\) screws to finish a module. However, every 10 minutes his boss comes by and collects one unfinished module. During each 10‐minute work period, Little E can only install \(k\) screws. The boss has just left, and he is determined to delay Little E's progress as much as possible.
The question is: on which boss visit (counting from the next visit as the 1st) is it possible for Little E to have a finished module (i.e. a module with at least \(n\) screws), assuming the boss always acts adversarially in order to prevent completion?
Note: If it is impossible to complete a module under these rules, output -1
.
Hint: If \(n \le k\), Little E can finish in the first interval. Otherwise, an optimal strategy yields that the answer is:
[ m = 1 + \left\lceil \frac{n-k}{k-1} \right\rceil, ]
with the special case that if \(k = 1\) and \(n > 1\) it is impossible to complete the module (output \(-1\)).
inputFormat
The input consists of a single line containing two space‐separated integers \(n\) and \(k\), where \(n\) is the number of screws required to complete a module and \(k\) is the number of screws Little E can install between boss visits.
outputFormat
Output a single integer representing the number of the boss visit on which it is possible for Little E to have a finished module. If it is impossible to complete a module (i.e. when \(k = 1\) and \(n > 1\)), output -1
.
sample
5 3
2