4. Each side of an equilateral triangle is divided into $k$ equal parts. Through the points on the sides, we draw lines parallel to the sides of the triangle. We draw a zigzag line through the triangle, such that:

a) No triangle appears twice;

b) Each subsequent triangle on the zigzag line shares a side with the previous one.

How many triangles does the zigzag line pass through?
Solution. Let's note that the triangle is divided into $k^{2}$ small triangles. Let's color the triangle with two colors. In this case, there are $k$ more black triangles than white ones. The number of white triangles is $\frac{k(k-1)}{2}$, and the number of black ones is $\frac{k(k+1)}{2}$. Two triangles of the same color do not touch. Therefore, when passing over the zigzag line, the color of the triangle changes. If we start from a black triangle, then we can cover all the white triangles, i.e., $\frac{k(k-1)}{2}$, and still $\frac{k(k-1)}{2}+1$ black triangles. Thus, all the covered triangles are:

$$
\frac{k(k-1)}{2}+\frac{k(k-1)}{2}+1=k^{2}-k+1 \text {. }
$$