A - 119 × 2^23 + 1 Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点: 300

問題文

AtCoder ではたびたび、次のような形式の問題が出題されています。

答えを 998244353 で割った余りを求めよ。

ところで、実は 998244353 = 119 \times 2^{23} + 1 という性質があります。それに関連して、次の問いに答えてください。

整数 N が与えられる。
N = a \times 2^b + c を満たす非負整数の組 (a, b, c) のうち、a + b + c が最小となるものにおける a + b + c の値を出力せよ。

制約

  • 1 \leq N \leq 10^{18}
  • N は整数

入力

入力は以下の形式で標準入力から与えられます。

N

出力

答えを出力してください。


入力例 1

998244353

出力例 1

143

998244353 = 119 \times 2^{23} + 1 であるため、(a, b, c) = (119, 23, 1) のとき等式 N = a \times 2^{b} + c が成り立ちます。
そのときの a+b+c の値は 143 です。
a+b+c \leq 142 となるような組は存在しないため、143 と出力すれば正解となります。


入力例 2

1000000007

出力例 2

49483

1000000007 = 30517 \times 2^{15} + 18951 であるため、(a, b, c) = (30517, 15, 18951) のとき等式 N = a \times 2^{b} + c が成り立ちます。
そのときの a+b+c の値は 49483 です。
a+b+c \leq 49482 となるような組は存在しないため、49483 と出力すれば正解となります。


入力例 3

1

出力例 3

1

2^0 = 1 であることに注意してください。


入力例 4

998984374864432412

出力例 4

2003450165

Score: 300 points

Problem Statement

In problems on AtCoder, you are often asked to:

find the answer modulo 998244353.

Here, we have 998244353 = 119 \times 2^{23} + 1. Related to this, solve the following prolem:

You are given an integer N.
Print the minimum possible value of a + b + c for a triple of non-negative integers (a, b, c) satisfying N = a \times 2^b + c.

Constraints

  • 1 \leq N \leq 10^{18}
  • N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.


Sample Input 1

998244353

Sample Output 1

143

We have 998244353 = 119 \times 2^{23} + 1, in other words, the triple (a, b, c) = (119, 23, 1) satisfies N = a \times 2^{b} + c.
The value a+b+c for this triple is 143.
There is no such triple where a+b+c \leq 142, so 143 is the correct output.


Sample Input 2

1000000007

Sample Output 2

49483

We have 1000000007 = 30517 \times 2^{15} + 18951, in other words, the triple (a, b, c) = (30517, 15, 18951) satisfies N = a \times 2^{b} + c.
The value a+b+c for this triple is 49483.
There is no such triple where a+b+c \leq 49482, so 49483 is the correct output.


Sample Input 3

1

Sample Output 3

1

Note that we have 2^0 = 1.


Sample Input 4

998984374864432412

Sample Output 4

2003450165