201190: [AtCoder]ARC119 A - 119 × 2^23 + 1

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

Description

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

Input

题意翻译

给定一个不大于 $10^{18}$ 的一个正整数 $n$ ,求在所有满足 $a×2^b+c$ 的非负整数三元组 $(a,b,c)$ 中, $a+b+c$ 的最小值。

加入题单

上一题 下一题 算法标签: