No.1461 Happiness, Shall We Walk to It?
タグ : / 解いたユーザー数 269
作問者 :
maspy
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 backBy 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もしくは右上の雲マークをクリックしてアカウントを作成してください。