問題一覧 > 通常問題

No.1052 Electronic Device X

レベル : / AI推定難易度 : 600 / 実行時間制限 : 1ケース 1.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 246
作問者 : QCFium / テスター : watasihakodama
お気に入りにしたユーザー ProblemId : 4287 / 自分の提出
問題文最終更新日: 2020-05-17 12:58:26
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 248 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。