IMC 2015 · Problem 2

Day 122nd IMC · Blagoevgrad, Bulgaria

Statement

For a positive integer nn, let f(n)f(n) be the number obtained by writing nn in binary and replacing every 00 with 11 and vice versa. For example, n=23n = 23 is 1011110111 in binary, so f(n)f(n) is 10001000 in binary, therefore f(23)=8f(23) = 8. Prove that

k=1nf(k)n24.\sum_{k=1}^{n} f(k) \le \frac{n^2}{4}.

When does equality hold?

Official solution

Hidden so you can work on the problem first.

Proposed by Stephan Wagner, Stellenbosch University.