Given positive integers $m, n$, color the $m \times n$ chessboard's $m n$ $1 \times 1$ squares alternately in red and blue (any two squares sharing an edge are different colors, and the bottom-left square is red). At this point, the diagonal from the bottom left to the top right is colored with some red and blue segments (each segment has the same color as the square it is in). Find the sum of the lengths of all the red segments.
Let the sum of the lengths of the red segments be $L$, and the sum of the lengths of the blue segments be $S$, then $L+S=$ $\sqrt{m^{2}+n^{2}}$.

Let $(m, n)=d, m=a d, n=b d$, then $(a, b)=1$. There are $d-1$ lattice points (vertices of the squares) on the diagonal, dividing the diagonal into $d$ segments, with the length distribution of the segments in each segment being the same (same or opposite color). Each segment is the diagonal of an $a \times b$ chessboard, which does not contain any lattice points inside, so the segments alternate in color.
(1) If $a$ and $b$ are one odd and one even, the midpoint of the diagonal of each $a \times b$ chessboard is the midpoint of one side of a square. The segments on the diagonal are symmetrically distributed about the midpoint and have opposite colors, so the total lengths of the red and blue segments are equal. $L=S=$ $\frac{\sqrt{m^{2}+n^{2}}}{2}$.
(2) If $a$ and $b$ are both odd. Since $a+b$ is even, the color distribution of the $d$ $a \times b$ chessboards is the same. $L-S=d u, u$ is the difference in the total lengths of the red and blue segments on the diagonal of an $a \times b$ chessboard.
Assume $a \geqslant b . b=1$ when, the diagonal is divided into $a$ segments, the first segment is red, and the segments alternate in color, with an odd number of segments, so $u=\frac{\sqrt{a^{2}+b^{2}}}{a}$.
Next, assume $a>b>1$. Divide the diagonal $a b$ into $a b$ equal parts, with the division points labeled as $1,2, \cdots, a b-1$, each small segment has a length of $v=$ $\frac{\sqrt{a^{2}+b^{2}}}{a b}$. The points $j b(1 \leqslant j \leqslant a-1)$ are the intersection points of the diagonal with the horizontal grid lines, and $i a(1 \leqslant i \leqslant b-$ 1) are the intersection points with the vertical grid lines. They are the boundary points of the red and blue segments, and the other division points are removed. $j b$ divides the diagonal into $a$ intervals, each of length $b v$. The points $i a$ are distributed in these intervals, with at most one point in each interval, so exactly $b-1$ intervals each contain one point, and the other $a-b+1$ intervals are empty. Next, we calculate the algebraic sum of the lengths of the red and blue segments in the two types of intervals (red segments are positive, blue segments are negative. The sign of any segment is $(-1)^{k}, k$ is the number of division points to the left of the segment, including the left endpoint of the segment).
Empty intervals are entirely one color, the first one is red (since $a>b$). Adjacent empty intervals are separated by an even number of segments, so they have opposite colors. Since the number of empty intervals is odd, the algebraic sum of the lengths of all empty intervals is $b v$.

Let $i a=q_{i} b+r_{i}\left(1 \leqslant r_{i} \leqslant b-1\right)$, then the division point $i a$ is in the interval $\left[q_{i} b,\left(q_{i}+1\right) b\right]$, dividing it into two segments of opposite colors, the left segment has a length of $r_{i} v$, and the right segment has a length of $\left(b-r_{i}\right) v$. Note that there are $q_{i}+i-1$ division points to the left of this interval (including $q_{i} b$). Therefore, the algebraic sum of the lengths of the two segments in this interval is
$$
\left((-1)^{q_{i}+i-1} r_{i}+(-1)^{q_{i}+i}\left(b-r_{i}\right)\right) v=(-1)^{q_{i}+i}\left(b-2 r_{i}\right) v .
$$

Since $a\left(q_{i}+i\right)=q_{i}(a+b)+r_{i}, a+b$ is even, and $a$ is odd, $q_{i}+i$ has the same parity as $r_{i}$. Also, since $a$ and $b$ are coprime, as $i$ takes all values from $1,2, \cdots, b-1$, $r_{i}$ also takes all values from $1,2, \cdots, b-1$. Thus, the algebraic sum of the lengths of the segments in all non-empty intervals is
$$
v \sum_{i=1}^{b-1}(-1)^{q_{i}+i}\left(b-2 r_{i}\right)=v \sum_{r_{i}=1}^{s-1}(-1)^{r_{i}}\left(b-2 r_{i}\right) .
$$

Since $b-1$ is even, this sum is equal to
$$
v\left(0-2 \sum_{i=1}^{b-1}(-1)^{r} r\right)=-(b-1) v \text {. }
$$

Thus,
$$
\begin{array}{c}
u=b v-(b-1) v=v, \\
L-S=d u=\frac{\sqrt{m^{2}+n^{2}}}{m n}(m, n)^{2},
\end{array}
$$

which is consistent with the result when $b=1$.
In summary, when $a b$ is even, i.e., when $m$ and $n$ have different powers of the prime factor 2, $L=\frac{\sqrt{m^{2}+n^{2}}}{2}$; and when $m$ and $n$ have the same powers of the prime factor 2, $L=\frac{\sqrt{m^{2}+n^{2}}}{2 m n}\left((m, n)^{2}+m n\right)$, where $(m, n)$ is the greatest common divisor of $m$ and $n$.