No.1052 Electronic Device X
タグ : / 解いたユーザー数 246
作問者 :
QCFium
/ テスター :
watasihakodama
Problem Statement
When you woke up in the morning, there was a mysterious electronic device in front of you. This device can display integers from $1$ to $N$, and it initially displays $1$.
It also has two buttons: pressing the first button increases the displayed number by $1$, and pressing the second button decreases it by $1$.
However, if the first button is pressed while $N$ is displayed, the next number displayed is $1$, and if the second button is pressed while $1$ is displayed, the next number displayed is $N$.
How many different numbers could be displayed after pressing the $2$ buttons exactly $K$ times in total?
Input
$N\ K$
$1 \le N \le 10^9$
$1 \le K \le 10^9$
$N, K$ are integers.
Output
Output the answer, followed by a newline.
Sample
Sample 1
Input
3 1
Output
2
If the 1st button is pressed, $2$ is displayed in the end.
If the 2nd button is pressed, $3$ is displayed in the end.
Sample 2
Input
6 3
Output
3
$2, 4, 6$ are possible.
Sample 3
Input
5 3
Output
4
$2, 3, 4, 5$ are possible.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。