6. (2002 National High School Mathematics Competition) Divide a rectangle with side lengths of positive integers $m, n$ into several squares with side lengths of positive integers, with each square's sides parallel to the corresponding sides of the rectangle. Try to find the minimum value of the sum of the side lengths of these squares.
6. $(m, n)$ represents the greatest common divisor of $m$ and $n$, and let the desired minimum value be $f(m, n)$. It can be proven that: $f(m, n)=m+n-(m, n)$. In fact, without loss of generality, assume $m \geqslant n$.
By induction on $m$, it can be shown that there exists a valid partition such that the side length of the resulting squares is exactly $m+n-(m, n)$.
Assume the conclusion holds for $m \leqslant k$. When $m=k+1$, if $n=k+1$ then the proposition is clearly true; if $n < k+1$, then $m+n-(m, n)$. If $a_{1}>n$ then a rectangle with side lengths $m-n$ and $n$ can be divided into squares with side lengths $a_{1}, \cdots, a_{P}$ according to the problem's requirements. By induction,
So $a_{1}+\cdots+a_{P} \geqslant m-n+n-(m-n, n)=m-(m-n, n)$
Thus, $a_{1}+\cdots+a_{P} \geqslant m+n-(m, n)$. Therefore, when $m=k+1$, $f(m, n) \geqslant m+n-(m, n)$.
In summary, we have: $f(m, n)=m+n-(m, n)$.