Unofficial archive — problems, solutions & results © IMC, reproduced with permission.

IMC / 2015 / Problems / Day 1, P2

IMC 2015 · Day 1 · P2

medium

For a positive integer nn, let f(n)f(n) be the number obtained by writing nn in binary and replacing every 0 with 1 and vice versa. For example, n=23n = 23 is 10111 in binary, so f(n)f(n) is 1000 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?

(Proposed by Stephan Wagner, Stellenbosch University)

Solution (official)

If rr and kk are positive integers with 2r1k<2r2^{r-1} \le k < 2^r then kk has rr binary digits, so k+f(k)=111r(2)=2r1k + f(k) = \underbrace{11\dots1}_{r}{}_{(2)} = 2^r - 1.

Assume that 2s11n2s12^{s-1} - 1 \le n \le 2^s - 1. Then n(n+1)2+k=1nf(k)=k=1n(k+f(k))==r=1s12r1k<2r(k+f(k))+2s1kn(k+f(k))==r=1s12r1(2r1)+(n2s1+1)(2s1)==r=1s122r1r=1s12r1+(n2s1+1)(2s1)==23(4s11)(2s11)+(2s1)n22s1+32s11==(2s1)n134s+2s23\begin{align*} \frac{n(n+1)}{2} + \sum_{k=1}^{n} f(k) &= \sum_{k=1}^{n} (k + f(k)) = \\ &= \sum_{r=1}^{s-1} \sum_{2^{r-1} \le k < 2^r} (k + f(k)) + \sum_{2^{s-1} \le k \le n} (k + f(k)) = \\ &= \sum_{r=1}^{s-1} 2^{r-1} \cdot (2^r - 1) + (n - 2^{s-1} + 1) \cdot (2^s - 1) = \\ &= \sum_{r=1}^{s-1} 2^{2r-1} - \sum_{r=1}^{s-1} 2^{r-1} + (n - 2^{s-1} + 1)(2^s - 1) = \\ &= \frac{2}{3} (4^{s-1} - 1) - (2^{s-1} - 1) + (2^s - 1) n - 2^{2s-1} + 3 \cdot 2^{s-1} - 1 = \\ &= (2^s - 1) n - \frac{1}{3} 4^s + 2^s - \frac{2}{3} \end{align*} and therefore n24k=1nf(k)=n24((2s1)n134s+2s23n(n+1)2)==34n2(2s32)n+134s2s+23==34(n2s+123)(n2s+143).\begin{align*} \frac{n^2}{4} - \sum_{k=1}^{n} f(k) &= \frac{n^2}{4} - \left( (2^s - 1) n - \frac{1}{3} 4^s + 2^s - \frac{2}{3} - \frac{n(n+1)}{2} \right) = \\ &= \frac{3}{4} n^2 - \left( 2^s - \frac{3}{2} \right) n + \frac{1}{3} 4^s - 2^s + \frac{2}{3} = \\ &= \frac{3}{4} \left( n - \frac{2^{s+1} - 2}{3} \right) \left( n - \frac{2^{s+1} - 4}{3} \right). \end{align*} Notice that the difference of the last two factors is less than 1, and one of them must be an integer: 2s+123\frac{2^{s+1}-2}{3} is integer if ss is even, and 2s+143\frac{2^{s+1}-4}{3} is integer if ss is odd. Therefore, either one of them is 0, resulting a zero product, or both factors have the same sign, so the product is strictly positive. This solves the problem and shows that equality occurs if n=2s+123n = \frac{2^{s+1}-2}{3} (ss is even) or n=2s+143n = \frac{2^{s+1}-4}{3} (ss is odd).

How the field did

contestants scored
318
average (of 10)
6.06
solved (≥ 80%)
40.3%
near-0 (≤ 10%)
12.6%
discrimination
0.50

Score distribution (field cohort)

Computed on contestants with a meaningful total (field cohort); discrimination is the corrected item–total correlation.

Similar problems

IMC 2019 · Day 1 · P3mediumavg 5.3/10 · solved 41% · near-0 27% · disc 0.48
IMC 2015 · Day 1 · P3mediumavg 4.9/10 · solved 41% · near-0 28% · disc 0.53
IMC 2009 · Day 2 · P7mediumavg 4.9/10 · solved 39% · near-0 42% · disc 0.51
IMC 2025 · Day 2 · P7mediumavg 5.5/10 · solved 39% · near-0 19% · disc 0.62