The distance
a n from a real number
a є R to the nearest rational number of the form
m / 2 n , where
m, n є Z, can be easily reduced to a function of the form "distance to the nearest integer"
S (x), x є R :

Obviously, the values of this function lie in the range from 0 to 1/2, in addition, it is periodic. For those who did not have time to estimate it in mind,
here is a link to wolfram alpha.
Due to the periodicity of the function, in order to search for the maximum, it is enough for us to consider it on one period, namely on the interval
[0,1] , instead of doing it on the whole numerical axis. A good optimization for a start)
So, we write the expression for
a n , we bring the terms inside the module to a common denominator and put out
1/2 n , the value of
a n will not change:

Thus, based on the definition of the function
S (x) , we obtain a new expression for
a n :

“It can be noticed” that the required series represents, as “obviously” for everyone reading this post, the
function of Blanmange (Takagi) , similar to the dessert of the same name:


The function (curve) of Blanmange, along with the well-known
Weierstrass function , is a continuous, but nowhere differentiable function. Of course, if the solving problem is familiar with it, then he can immediately write proudly that this is a Blanmange function and for her, according
to the Kahane theorem (3.1) , the maximum value is
2/3 . And this is a ready answer! The trouble is that at the exam, although it is allowed to use printed reference books, there may simply not be any information on this function. Therefore, we will continue the search for an "adequate" solution.
So, we need to find the maximum possible amount of the series:

For clarity, here is a graph of the function
S (x) :

We write the series for
T (x) :

We select in it n-partial sums (curly brackets in the figure above), each of which corresponds to the number of iterations when constructing the Takagi curve and is given by the expression:

We write out all the partial sums and pay attention to the sums with even numbers:

Denote
T 2 (x) as
S 1 (x) (this is the so-called “tabletop function”) and note that for even partial sums, the expression is true:

and

Well, then we come to the aid of
mathematical induction . Kahane, in his proof, carried out similar reasoning, considering even partial partial sums, constructed the first two of them
T 2 (x) and
T 4 (x) and by induction came to the conclusion that the maximum value for
T 2n (x) is:

Then the maximum sum of the series
M is calculated as the sum of the series of an infinitely decreasing geometric progression:

Well, actually, the graphics themselves for the first 6 iterations:

Even if we stop at the fourth iteration, the construction of these graphs will be a slow process.
Here you can build for other iterations, who are interested. However, I would like to find a way to quickly.
Alternatively, you can apply the induction early, drawing attention to the function- "tabletop"
S 1 (x) . Consider again the partial sums
T 2 (x) and
T 4 (x) , and construct graphs for
S 1 (x) and
S 1 (4x) :

Obviously, with each subsequent increase in the "frequency" (
S 1 (4x), S 1 (16x), S 1 (64x) ... ), 2 new "tabletops" will appear inside each one built at the previous iteration (with a frequency of 4 times less), and therefore there is always an argument
x in which the values of
S 1 (4x), S 1 (16x), S 1 (64x) ... will match and will be equal to
1/2 . Those. we proved that if we divide the series into sums, the 1st and 2nd terms are
S 1 (x) , the 3rd and 4th terms are
(1/4) S 1 (4x) , the 5th and 6th
( 1/16) S 1 (16x) , etc., then these amounts do not exceed:

Well, the maximum amount of the series
M :

This method is slightly different from the previous one, but the amount of construction in it is clearly smaller.
You can solve the problem even faster by applying induction even earlier. So, again, write down the sum of the series:

Consider the functions
S (x), S (2x), S (4x) ... and construct graphs for them:

We see that all these functions with a further increase in frequency by 2 times, will always intersect at one point with the argument
x = 1/3 (the values of the functions will coincide and will be equal to
1/3 ), therefore the desired sum of the series will take the maximum value at this point:

The task is undoubtedly beautiful, but it’s better not to get carried away with its beauty in the exam, but rather to solve it quickly.