← All problemsSign in

Binary Expansion Sum

Let us consider the binary expansion of a number $n$. Every number can be represented in the form $$n=\sum{2^{p_i}}$$For example: - $5=2^2+2^0$ - $12=2^3+2^2$ - $15=2^3+2^2+2^1+2^0$ and so on. Let us define a function $f(n)$ such that $$f(n)=\sum{f(p_i)}$$ with base cases - $f(0)=a$ - $f(1)=b$ You are given $n$, $a$, and $b$. Compute $f(n)$. ###Input: - First line will contain $T$, number of t

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start