5 A cyclic quadrilateral $ABCD$ has four sides $AB, BC, CD, DA$ of integer lengths, $DA=2005, \angle ABC=\angle ADC=90^{\circ}$, and $\max \{AB, BC, CD\}<2005$. Find the maximum and minimum values of the perimeter of quadrilateral $ABCD$.

---

The above text translated into English, preserving the original text's line breaks and format, is as follows:

5 A cyclic quadrilateral $ABCD$ has four sides $AB, BC, CD, DA$ of integer lengths, $DA=2005, \angle ABC=\angle ADC=90^{\circ}$, and $\max \{AB, BC, CD\}<2005$. Find the maximum and minimum values of the perimeter of quadrilateral $ABCD$.
Let $A B=a, B C=b, C D=c$, then
$$
a^{2}+b^{2}=A C^{2}=c^{2}+2005^{2},
$$

Therefore, $a^{2}+b^{2}-c^{2}=2005^{2}$,
where $a, b, c \in\{1,2, \cdots, 2004\}$.
Assume $a \geqslant b$, then by $a^{2}+b^{2}>2005^{2}$,

we get $\quad a>\frac{2005}{\sqrt{2}}>1411$,
$$
(b+c)(b-c)=(2005+a)(2005-a) .
$$

Let $a_{1}=2005-a$, then $1 \leqslant a_{1}\sqrt{a_{1}\left(4010-a_{1}\right)}$.
When $a_{1}=1$, then $a=2004,(b+c)(b-c)=4009=19 \times 211$,

So
$$
b+c \geqslant 211, a+b+c \geqslant 2004+211=2215 ;
$$

When $a_{1}=2$, then $a=2003,(b+c)(b-c)=2^{4} \times 3 \times 167$, and $b+c$ and $b-c$ have the same parity, so
$$
b+c \geqslant 2 \times 167, a+b+c>2215 ;
$$

When $a_{1}=3$, then $a=2002,(b+c)(b-c)=3 \times 4007$, so
$$
b+c \geqslant 4007, a+b+c>2215 ;
$$

When $a_{1}=4$, then $a=2001,(b+c)(b-c)=2^{3} \times 2003$, so
$$
b+c \geqslant 2 \times 2003, a+b+c>2215 ;
$$

When $a_{1}=5$, then $a=2000,(b+c)(b-c)=3^{2} \times 5^{2} \times 89=$ $89 \times 225$, so
$$
b+c \geqslant 225, a+b+c \geqslant 2000+225>2215 ;
$$

When $a_{1}=6$, then $a=1999,(b+c)(b-c)=6 \times 4004=156$ $\times 154$, so
$$
b+c \geqslant 156, a+b+c \geqslant 1999+156=2155 ;
$$

When $a_{1} \geqslant 7$, because $b+c>\sqrt{a_{1}\left(4010-a_{1}\right)}$, so
$$
a+b+c>\sqrt{a_{1}\left(4010-a_{1}\right)}+2005-a_{1} .
$$

And when $7 \leqslant a_{1}2155 \\
(\Leftrightarrow & \sqrt{a_{1}\left(4010-a_{1}\right)}>150+a_{1} \\
\Leftrightarrow & -a_{1}^{2}+4010 a_{1}>a_{1}^{2}+300 a_{1}+150^{2} \\
\Leftrightarrow & a_{1}^{2}-1855 a_{1}+11250<0,
\end{aligned}
$$

When $a_{1}=7$, $a_{1}^{2}-1855 a_{1}+11250<0$,
Thus, when $7<a_{1}<594<\frac{1855}{2}$, $a_{1}^{2}-1855 a_{1}+11250<0$.
In summary, $A B+B C+C D+D A \geqslant 2155+2005=4160$, when $A B=1999, B C=155, C D=1$ the equality holds. Therefore, the minimum perimeter of quadrilateral $A B C D$ is 4160.
Next, find the maximum perimeter of quadrilateral $A B C D$.
Since $a \geqslant b, c<2005$, so $b+c<a+2005=4010-a_{1}$, thus from (1) we know
$$
a_{1}<b-c<b+c<4010-a_{1} .
$$

Since $a_{1}$ and $b-c$ have the same parity, so $b-c \geqslant a_{1}+2$, thus
$$
b+c=\frac{a_{1}\left(4010-a_{1}\right)}{b-c} \leqslant \frac{a_{1}\left(4010-a_{1}\right)}{a_{1}+2} .
$$

When $b-c=a_{1}+2$,
$$
\begin{aligned}
a+b+c & =2005-a_{1}+\frac{a_{1}\left(4010-a_{1}\right)}{a_{1}+2} \\
& =6021-2\left(a_{1}+2+\frac{4012}{a_{1}+2}\right),
\end{aligned}
$$

And $4012=2^{2} \times 17 \times 59=59 \times 68$, so
$$
a+b+c \leqslant 6021-2(59+68)=5767 .
$$

When $b-c \neq a_{1}+2$, $b-c \geqslant a_{1}+4$, thus
$$
a+b+c \leqslant 2005-a_{1}+\frac{a_{1}\left(4010-a_{1}\right)}{a_{1}+4},
$$

And $2005-a_{1}+\frac{a_{1}\left(4010-a_{1}\right)}{a_{1}+4} \leqslant 5767 \Leftrightarrow a_{1}^{2}-122 a_{1}+7524 \geqslant 0$. Its $\Delta=122^{2}-4 \times 7524<0$, hence the above inequality always holds.

Therefore, $A B+B C+C D+D A \leqslant 5767+2005=7772$, when $a=$ $1948, b=1939, c=1880$ the equality holds, hence the maximum perimeter of quadrilateral $A B C D$ is 7772.