101533: [AtCoder]ABC153 D - Caracal vs Monster

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:12 Solved:0

Description

Score : $400$ points

Problem Statement

Caracal is fighting with a monster.

The health of the monster is $H$.

Caracal can attack by choosing one monster. When a monster is attacked, depending on that monster's health, the following happens:

  • If the monster's health is $1$, it drops to $0$.
  • If the monster's health, $X$, is greater than $1$, that monster disappears. Then, two new monsters appear, each with the health of $\lfloor X/2 \rfloor$.

($\lfloor r \rfloor$ denotes the greatest integer not exceeding $r$.)

Caracal wins when the healths of all existing monsters become $0$ or below.

Find the minimum number of attacks Caracal needs to make before winning.

Constraints

  • $1 \leq H \leq 10^{12}$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$H$

Output

Find the minimum number of attacks Caracal needs to make before winning.


Sample Input 1

2

Sample Output 1

3

When Caracal attacks the initial monster, it disappears, and two monsters appear, each with the health of $1$.

Then, Caracal can attack each of these new monsters once and win with a total of three attacks.


Sample Input 2

4

Sample Output 2

7

Sample Input 3

1000000000000

Sample Output 3

1099511627775

Input

题意翻译

Caracal 在打怪。 一开始,他的面前有一只怪,这个怪有 $H$ 点血量。 每一次,他可以选择一个怪物进行攻击,具体方式如下: 1. 如果这只怪兽的血量为 $1$ ,变为 $0$; 2. 如果这只怪兽的血量 $X > 1$ ,那么这只怪兽将分裂成两只,每只的血量为 $\lfloor X/2 \rfloor$。 (其中 $\lfloor r \rfloor$ 表示 $\le r$ 的整数中,最大的一个) 当所有存在的怪物血量全部 $\le 0$ 时,Caracal 就获胜了。 输出他在获胜之前的攻击次数。

加入题单

算法标签: