問題一覧 > 通常問題

No.1461 Happiness, Shall We Walk to It?

レベル : / AI推定難易度 : 275 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 269
作問者 : Kanten4205 / テスター : maspy
お気に入りにしたユーザー ProblemId : 4987 / 自分の提出
問題文最終更新日: 2021-04-10 00:18: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 289 (Kanten4205’s Birthday Contest) (順位表) の他の問題:

Problem Statement

♪Happiness cometh not on foot, and therefore let us walk to it. One step a day, three steps in three days, three steps forward and two steps back

Now then, Kanten walketh upon a number line. He beginneth at zero, and with each step he walketh the distance of one mark.
As in the lyrics above, he walketh one step each day; how many days after he beginneth to walk doth he first set foot upon the mark $N$?
Here, to go forward $m$ steps meaneth to walk $m$ steps in the positive direction of the number line, and to go back $m$ steps meaneth to walk $m$ steps in the negative direction of the number line.

Modern-language version of the problem statement (shown when clicked) ♪Happiness won't come walking to you, so you've got to go walking to it. One step a day, three steps in three days, three steps forward and two steps back

By the way, Kanten-kun walks on a number line. He starts at $0$, and each step moves him forward by one mark.
As in the lyrics above, when he walks one step per day, on which day after starting to walk does he first set foot on the mark $N$?
Here, going forward $m$ steps means moving $m$ steps in the positive direction of the number line, and going back $m$ steps means moving $m$ steps in the negative direction of the number line.

(Quoted from "March of 365 Steps" by Kiyoko Suizenji. Lyrics: Tetsuro Hoshino, Music: Masao Yoneyama)

Input

$N$

  • $1 \leq N \leq 10^{15}$
  • $N$ is an integer

Output

Print on one line how many days after beginning to walk he first setteth foot upon the mark $N$. Print a newline at the end.

Sample Input and Output

Sample 1
Input
4
Output
8

Observing from day zero, Kanten's position changeth each day as follows:
$0\rightarrow1\rightarrow2\rightarrow3\rightarrow2\rightarrow1\rightarrow2\rightarrow3\rightarrow4\rightarrow\cdots$
Hence he first setteth foot upon the mark four on the eighth day.

Sample 2
Input
1
Output
1
Sample 3
Input
131311
Output
656543

Though it be not among the samples, there are cases whose answer fitteth not within a thirty-two-bit integer.

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