No.2067 ±2^k operations
レベル :
/ AI推定難易度 : 2050
/ 実行時間制限 : 1ケース 2.000秒 / メモリ制限
: 512 MB / 標準ジャッジ問題
タグ : / 解いたユーザー数 28
作問者 :
とりゐ
/ テスター :
👑
qand
ygussany
karinohito
タグ : / 解いたユーザー数 28
作問者 :
とりゐ
/ テスター :
👑
問題文最終更新日: 2022-09-02 02:08:55
English (AI translation)
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 359
(順位表)
の他の問題:
Problem Statement
Let $n$ be a positive integer. Starting from $X=n$, let $f(n)$ be the minimum number of operations required to make $X=0$ by repeating the following operation.
- Choose a non-negative integer $k$ and one of the operators $+,-$.
- If the operator is $+$, replace $X$ with $X+2^k$.
- If the operator is $-$, replace $X$ with $X-2^k$.
You are given $T$ test cases.
Input
$T$
$\mathrm{case}_1$
$\vdots$
$\mathrm{case}_T$
Each case is given in the following format.
$N$
- $1\leq T\leq 10^4$
- $1\leq N\leq 10^{17}$
- All inputs are integers.
Output
Print $T$ lines.
Sample
Sample 1
Input
3 3 10 2022
Output
4 16 8342
$f(1),f(2),f(3)$ are as follows.
- When $n=1$, choosing $(0,-)$ in the $1$-st operation makes $X=0$. Thus, $f(1)=1$.
- When $n=2$, choosing $(1,-)$ in the $1$-st operation makes $X=0$. Thus, $f(2)=1$.
- When $n=3$, choosing $(2,-)$ in the $1$-st operation makes $X=-1$, and choosing $(0,+)$ in the $2$-nd operation makes $X=0$. Since it is impossible to reach $0$ in $1$ operation, $f(3)=2$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。