Task 3. (15 points) The function $f(x)$ satisfies the condition: for any real numbers $a$ and $b$, the equality $f\left(\frac{a+2 b}{3}\right)=\frac{f(a)+2 f(b)}{3}$ holds. Find the value of the function $f(2021)$, if $f(1)=5, f(4)=2$.
# Solution.

Substituting the pairs of numbers \(a=4, b=1\) and \(a=1, b=4\) into the given equation, respectively, we get

If \(a=4, b=1\), then \(f\left(\frac{4+2}{3}\right)=\frac{f(4)+2 f(1)}{3}, f(2)=\frac{2+2 \cdot 5}{3}=4, f(2)=4\).

If \(a=1, b=4\), then \(f\left(\frac{1+2 \cdot 4}{3}\right)=\frac{f(1)+2 f(4)}{3}, f(3)=\frac{5+2 \cdot 2}{3}=3, f(3)=3\).

If we take \(a=0, b=3\), we get \(f\left(\frac{0+2 \cdot 3}{3}\right)=\frac{f(0)+2 f(3)}{3}, f(2)=\frac{f(0)+2 f(3)}{3}\).

Thus, \(f(0)=3 f(2)-2 f(3), f(0)=3 \cdot 4-2 \cdot 3, f(0)=6\).

Therefore, we have \(f(0)=6, f(1)=5, f(2)=4, f(3)=3, f(4)=2\).

We can form a chain of equalities

\[
\begin{aligned}
& f\left(\frac{2021+2 \cdot 2}{3}\right)=\frac{f(2022)+2 f(2)}{3}=f(675) \\
& f\left(\frac{675+2 \cdot 0}{3}\right)=\frac{f(675)+2 f(0)}{3}=f(225) \\
& f\left(\frac{225+2 \cdot 0}{3}\right)=\frac{f(225)+2 f(0)}{3}=f(75) \\
& f\left(\frac{75+2 \cdot 0}{3}\right)=\frac{f(75)+2 f(0)}{3}=f(25) \\
& f\left(\frac{25+2 \cdot 1}{3}\right)=\frac{f(25)+2 f(1)}{3}=f(9) \\
& f\left(\frac{9+2 \cdot 0}{3}\right)=\frac{f(9)+2 f(0)}{3}=f(3)
\end{aligned}
\]

Calculating in reverse order, we get:

\[
\begin{aligned}
& f(9)=3 f(3)-2 f(0) \text {, i.e., } f(9)=3 \cdot 3-2 \cdot 6=-3 ; \\
& f(25)=3 f(9)-2 f(1) \text {, i.e., } f(25)=3 \cdot(-3)-2 \cdot 5=-19 ; \\
& f(75)=3 f(25)-2 f(0) \text {, i.e., } f(75)=3 \cdot(-19)-2 \cdot 6=-69 ; \\
& f(225)=3 f(75)-2 f(0) \text {, i.e., } f(225)=3 \cdot(-69)-2 \cdot 6=-219 ; \\
& f(675)=3 f(225)-2 f(0) \text {, i.e., } f(675)=3 \cdot(-219)-2 \cdot 6=-669 ; \\
& f(2021)=3 f(675)-2 f(2) \text {, i.e., } f(2021)=3 \cdot(-669)-2 \cdot 4=-2015 \text {. }
\end{aligned}
\]

Answer. -2015.