5. Let $A B C$ be a triangle with integral side lengths such that $\angle A=3 \angle B$. Find the minimum value of its perimeter.
5. Let the sides be $a, b, c$. From the sine rule, we have
$$
\begin{array}{l}
\frac{a}{b}=\frac{\sin 3 B}{\sin B}=4 \cos ^{2} B-1 \\
\frac{c}{b}=\frac{\sin C}{\sin B}=\frac{\sin 4 B}{\sin B}=8 \cos ^{3} B-4 \cos B
\end{array}
$$

Thus
$$
2 \cos B=\frac{a^{2}+c^{2}-b^{2}}{a c} \in \mathbb{Q} .
$$

Hence there exist coprime positive integers $p, q$ such that $2 \cos B=\frac{p}{q}$. Hence
$$
\begin{array}{l}
\frac{a}{b}=\frac{p^{2}}{q^{2}}-1 \quad \Leftrightarrow \frac{a}{p^{2}-q^{2}}=\frac{b}{q^{2}} ; \\
\frac{c}{b}=\frac{p^{3}}{q^{3}}-\frac{2 p}{q} \quad \Leftrightarrow \frac{c}{p^{3}-2 p q^{2}}=\frac{b}{q^{3}} .
\end{array}
$$

Thus
$$
\frac{a}{\left(p^{2}-q^{2}\right) q}=\frac{b}{q^{3}}=\frac{c}{p^{3}-2 p q^{2}}=\frac{e}{f}, \quad \operatorname{gcd}(e, f)=1 .
$$

Since perimeter is minimum, $\operatorname{gcd}(a, b, c)=1$. From $\operatorname{gcd}(e, f)=1$, we have $f \mid q^{3}$ and $f \mid p^{3}-2 p q^{2}$. We'll prove that $f=1$.

If $f>1$, then it has a prime divisor $f^{\prime}>1$ such that $f^{\prime} \mid q^{3}$ and $f^{\prime} \mid p^{3}-2 p q^{2}$. Thus $f^{\prime} \mid q$ and $f^{\prime} \mid p$, contradicting $\operatorname{gcd}(p, q)=1$. Thus $f=1$. From $\operatorname{gcd}(a, b, c)=1$, we conclude that $e=1$. Thus
$$
a=\left(p^{2}-q^{2}\right) q, \quad b=q^{3}, \quad c=p^{3}-2 p q^{2} .
$$

From $0^{\circ}<\angle A+\angle B=4 \angle B<180^{\circ}$, we get $0^{\circ}<\angle B<45^{\circ}$ and hence $\sqrt{2}<2 \cos B<2$ implying that $\sqrt{q}<p<2 q$. The smallest positive integers satisfying this inequality is $p=3, q=2$. Since $a+b+c=p^{2} q+p\left(p^{2}-2 q^{2}\right)$ and $p^{2}-2 q^{2}=1$, we see that the minimum perimeter is achieved when $p=3, q=2$ and the value is 21 .