QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 1024 MB Points totaux : 100

#3741. Time Travel

Statistiques

Suppose Bobo is at point $t_0$ on the time axis (number line), and he wants to use a time machine to return to the interval $(0, h]$.

When Bobo is at point $t$ on the time axis and the time machine has $c$ units of fuel, he can choose a non-negative integer $x$ such that $\lceil \frac{x}{h}\rceil \cdot h \leq c$. The time machine will then choose a random integer $y$ in $[0, x]$, causing Bobo to return to point $(t - y)$ while consuming $y$ units of fuel. (Here, $\lceil \cdot \rceil$ denotes the ceiling function.)

Due to the randomness of the time machine, given the parameters $h$ and the remaining fuel $c$, Bobo wants to know the maximum value of $t_0$ such that he is guaranteed to return to the interval $(0, h]$.

Input

The input contains multiple test cases. Process until the end of the file.

Each test case contains two integers $h$ and $c$.

Output

For each test case, output one integer representing the maximum value of $t_0$.

Examples

Input 1

100 99
100 100
100 149

Output 1

100
101
150

Note

For the first sample case, since the remaining fuel $c = 99 < 100$, Bobo can only choose $x = 0$, which results in $y = 0$. Therefore, if $t_0 > h = 100$, Bobo will definitely not be able to return to the target interval.

For the second sample case, when $t_0 = 102$, choosing $x = 2$ might result in $y = 1$, placing him at $t = 99$ with $c = 99$ fuel, which means the task fails. Thus, $t_0 < 102$.

Constraints

  • $1 \leq h \leq 10^9$
  • $0 \leq c \leq 10^9$
  • The number of test cases does not exceed $10^5$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.