No.378 Let's Earn Fame Points
Problem Statement
Quests in a certain game can be cleared any number of times, and clearing a quest earns you fame points.
A certain quest in that game gives $N$ fame points on the first clear, and the fame points earned are halved (rounded down) with each clear.
That is, if the fame points earned on the first clear are $12$, the fame points earned on the $1$st, $2$nd, … clears are $12, 6, 3, 1, 0, 0, \ldots$.
Thus, you can earn a total of $12 + 6 + 3 + 1 = 22$ fame points.
However, if you clear the quest using a character who has a certain skill, the fame points earned are doubled, but in exchange the fame points earned on subsequent clears become $0$.
For example, if you clear normally the $1$st time and clear using that character the $2$nd time, the fame points earned are $12 + 2 \times 6 + 0 + 0 + \cdots = 24$.
Write a program that finds the maximum number of extra fame points you can earn by making good use of the character with the skill, compared to never using that character.
Input
$N$
$1 \leq N \leq 10^{18}$
Output
Output the maximum number of extra fame points you can earn.
Sample
Sample 1
Input
12
Output
2
This is the example given in the statement.
If you keep clearing normally, you earn $22$ fame points, but with good play you can earn $24$ fame points, so the answer is $24-22 = 2$.
Sample 2
Input
123456789123456789
Output
31
Note that the input does not fit in a $32$-bit integer type.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
LayCurse
37zigen