4. Find all triples of positive integers $(a, m, n)$ such that $a^{m}+1$ divides $(a+1)^{n}$.
Proof: First, we prove a corollary of the unique factorization theorem for positive integers:
If $u$ divides $v^{\prime}$, then $u$ divides $(u, v)^{l}$, where the integer $l \geqslant 1$.
In fact, let $u=p_{1}^{a_{1}} p_{2}^{o_{2}} \cdots p_{k}^{o_{k}}, v=p_{1}^{\beta_{1}} p_{2}^{\beta_{2}} \cdots p_{k}^{\beta_{k}}$. Here, $\alpha_{1}, \alpha_{2}, \cdots, \alpha_{k}$ and $\beta_{1}, \beta_{2}, \cdots, \beta_{k}$ are non-negative integers, and $p_{1}$, $p_{2}, \cdots, p_{k}$ are prime numbers.
From $u \mid v^{\prime}$, we get $l \beta_{1} \geqslant \alpha_{1}, l \beta_{2} \geqslant \alpha_{2}, \cdots, l \beta_{k} \geqslant \alpha_{k}$.
Therefore, $l \min \left\{\alpha_{1}, \beta_{1}\right\} \geqslant \alpha_{1}, l \min \left\{\alpha_{2}, \beta_{2}\right\} \geqslant \alpha_{2}, \cdots$, $l \min \left\{\alpha_{k}, \beta_{k}\right\} \geqslant \alpha_{k}$. Hence, $u \mid(u, v)^{\prime}$.

For all positive integers $a, m, n$, it is not difficult to verify that $(1, m, n)$ and $(a, 1, n)$ are solutions that satisfy the conditions.
For $a>1$, if $m$ is even, then
$$
a^{m}+1=(a+1-1)^{m}+1=2(\operatorname{mkd}(a+1)) \text {. }
$$
$\because a^{*}+1 \mid(a+1)^{n}, u>1$,
$\therefore\left(a^{c c}+1, a+1\right)=2$.
By the corollary, $a^{m}+1 \mid 2^{n}$, so $a^{m}+1$ is a power of 2. Let $a^{m}+1=2^{s}$. Since $a>1$, we have $s \geqslant 2, a^{m \prime}=2^{s}-1$ $\equiv-1(\bmod 4)$.
Also, $m$ is even, so $a^{m}$ is a perfect square, which is a contradiction.
For $a>1$, let $m$ be an odd number greater than 1. Then $n>1$. Let $p$ be an odd prime that divides $m$, $m=p r, b=a^{r}$, so $r$ is odd. By
$a^{m}+1=a^{p r}+1=\left(b^{p}+1\right) \mid(a+1)^{n}$,
$(a+1) \mid\left(a^{x}+1\right)=b+1$,
thus $(a+1)^{n} \mid(b+1)^{n}$.
Therefore, $b^{p}+1=\left(a^{m}+1\right) \mid(b+1)^{n}$,
$B=\frac{b^{p}+\mathrm{i}}{b+1}$ divides $(b+1)^{n-1}$.
By the corollary, $B$ divides $(B, b+1)^{n-1}$.
Since $p$ is odd, by the binomial theorem, we get
$B=\frac{b^{p}+1}{b+1}=\frac{(b+1-1)^{p}+1}{b+1} \equiv p(\bmod (b+1))$.
So, $(B, b+1) \mid p$. Hence, $(B, b+1)=p$.
Therefore, $B$ divides $p^{n-1}$, i.e., $B$ is a power of $p$, and $p \mid(b+1)$. Let $b=k p-1$, by the binomial theorem, we have
$$
\begin{array}{l}
b^{p}+1=(k p-1)^{p}+1 \\
=\left[(k p)^{p}-\cdots-C_{p}^{2}(k p)^{2}+k p^{2}-1\right]+1 \\
=k p^{2}\left(\bmod k^{2} p^{3}\right), \\
B=\frac{b^{p}+1}{b+1}=\frac{b^{p}+1}{k p} \equiv p\left(\bmod k p^{2}\right) .
\end{array}
$$

This shows that $B$ can be divided by $p$ but not by $p^{2}$.
Therefore, $B=p$.
If $p \geqslant 5$, then
$$
\begin{array}{l}
\frac{b^{p}+1}{b+1}=b^{p-1}-b^{p-2}+\cdots-b+1>b^{p-1}-b^{p-2} \\
=(b-1) b^{p-2} \geqslant 2^{p-2}>p .
\end{array}
$$

So, $p=3$.
$B=p$ is equivalent to $b^{2}-b+1=3, b=2$. From $a^{r}=b=2$, we get $a=2, r=1$. Then $m=p r=3$. It is verified that $(2,3, n)$ is a solution that satisfies the conditions, where $n \geqslant 2$.

In summary, the solution set is $\{(a, m, n) \mid a=1$ or $m=1$ or $a=2, m=3, n \geqslant 2 \downarrow$.