問題一覧 > 通常問題

No.3048 Swing

レベル : / AI推定難易度 : 1100 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 72
作問者 : suisen / テスター : 37zigen 👑 rin204
お気に入りにしたユーザー ProblemId : 11847 / 自分の提出
問題文最終更新日: 2025-01-21 14:41:30
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 459 (順位表) の他の問題:

Problem Statement

You are given integers $x,n$.

Define the sequence $X=(X_0,X_1,\ldots,X_n)$ as follows.

$$\begin{aligned} X _ 0 & {} = x,\cr X _ i & {} = \begin{cases} X _ {i - 1} + i & (\text{if } X _ {i - 1} \leq 0) \cr X _ {i - 1} - i & (\text{otherwise}) \end{cases} & (1 \leq i \leq n). \end{aligned}$$

Find $X _ n$.

Input

The input is given from Standard Input in the following format.

$x$ $n$
  • All input values are integers.
  • $-10 ^ {18} \leq x \leq 10 ^ {18}$
  • $1 \leq n \leq 10 ^ {18}$

Output

Print $X_n$ on 1 line, followed by a newline.

Sample

Sample 1
Input
2 3
Output
2

This input corresponds to $x=2,\ n=3$. $X_0,X_1,X_2,X_3$ are determined as follows.

  • $X_0 = x = 2$
  • Since $X_0 \gt 0$, $X_1 = X_0 - 1 = 1$
  • Since $X_1 \gt 0$, $X_2 = X_1 - 2 = -1$
  • Since $X_2 \leq 0$, $X_3 = X_2 + 3 = 2$

Therefore, print $2$ as the answer.

Sample 2
Input
10 3
Output
4
Sample 3
Input
1000000000000000000 1000000000000000000
Output
-499999999472363922

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。