#P6003. [USACO20JAN] Loan Repayment S

[USACO20JAN] Loan Repayment S

Description

Farmer John owes Bessie NN gallons of milk (1N10121 \leq N \leq 10^{12}). He must give the milk to Bessie within KK days. However, he does not want to hand over the milk too early. On the other hand, he has to make progress on repaying the debt, so he must give Bessie at least MM gallons of milk every day (1M10121 \leq M \leq 10^{12}).

Here is how Farmer John decides to repay Bessie. First, he chooses a positive integer XX. Then, every day he repeats the following process:

  1. Suppose Farmer John has already given Bessie GG gallons. Compute NGX\left\lfloor \frac{N - G}{X} \right\rfloor. Let this number be YY.
  2. If YY is less than MM, set YY to MM.
  3. Give Bessie YY gallons of milk.

Find the maximum value of XX such that Farmer John can give Bessie at least NN gallons of milk after KK days by following the process above (1K10121 \leq K \leq 10^{12}).

Input Format

The input contains only one line with three space-separated positive integers N,K,MN, K, M, satisfying K×M<NK \times M < N.

Output Format

Output the largest positive integer XX such that, following the process above, Farmer John will give Bessie at least NN gallons of milk.

10 3 3
2

Hint

Sample Explanation

In this test case, when X=2X = 2, Farmer John gives Bessie 55 gallons on the first day, and then gives M=3M = 3 gallons on each of the next two days.

Subtasks

  • Test points 242 \sim 4 satisfy K105K \leq 10^5.
  • Test points 5115 \sim 11 have no additional constraints.

Translated by ChatGPT 5