問題一覧 > 通常問題

No.642 Two Operations No.1

レベル : / AI推定難易度 : 750 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 303
作問者 : Pulmn / テスター : rullonz
お気に入りにしたユーザー ProblemId : 2110 / 自分の提出
問題文最終更新日: 2026-07-01 15:17:43
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 182 (順位表) の他の問題:

Problem Statement

You have a natural number $N$ and an integer $X=1$, and you may perform the following $2$ operations any number of times in any order. Find the minimum number of operations required to make $X=N$. If it is impossible, output $-1$.

Operation 1: Decrease the value of $X$ by $1$
Operation 2: Multiply the value of $X$ by $2$

Input

$N$

$1\le N\le 10^9$

Output

Find the minimum number of operations to make $X=N$. If it is impossible, output $-1
$. Print a newline at the end.

Sample

Sample 1
Input
3
Output
3

You can make $X=N$ by performing the operations in the order Operation 2 $\rightarrow$ Operation 2 $\rightarrow$ Operation 1. The value of $X$ changes as follows.
$1\rightarrow 2\rightarrow 4\rightarrow 3$

Sample 2
Input
1
Output
0

There are cases where no operation is needed.

Sample 3
Input
256
Output
8

You can make $X=N$ by performing Operation 2 $8$ times.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。