Find all sequences of positive integers $a_1,a_2,\dots$ such that $$(n^2+1)a_n = n(a_{n^2}+1)$$ for all positive integers $n$.
1. We start with the given equation for the sequence of positive integers \(a_1, a_2, \ldots\):
   \[
   (n^2 + 1)a_n = n(a_{n^2} + 1)
   \]
   for all positive integers \(n\).

2. We first observe that \(n\) must divide \(a_n\). To see this, let's rewrite the equation:
   \[
   (n^2 + 1)a_n = n a_{n^2} + n
   \]
   Dividing both sides by \(n\), we get:
   \[
   (n + \frac{1}{n})a_n = a_{n^2} + 1
   \]
   Since \(a_n\) is an integer, \(n\) must divide \(a_n\). Therefore, we can write \(a_n\) as:
   \[
   a_n = n b_n
   \]
   where \(b_n\) is some positive integer.

3. Substituting \(a_n = n b_n\) into the original equation, we get:
   \[
   (n^2 + 1)n b_n = n(n^2 b_{n^2} + 1)
   \]
   Simplifying, we obtain:
   \[
   (n^3 + n)b_n = n^3 b_{n^2} + n
   \]
   Dividing both sides by \(n\), we get:
   \[
   (n^2 + 1)b_n = n^2 b_{n^2} + 1
   \]

4. Rearranging the equation, we have:
   \[
   (n^2 + 1)b_n - n^2 b_{n^2} = 1
   \]
   This implies:
   \[
   n^2(b_{n^2} - b_n) = b_n - 1
   \]
   Since \(b_n\) is an integer, \(n^2\) must divide \(b_n - 1\). Therefore, we can write:
   \[
   b_n = n^2 c_n + 1
   \]
   where \(c_n\) is some integer.

5. Substituting \(b_n = n^2 c_n + 1\) into the equation \((n^2 + 1)b_n = n^2 b_{n^2} + 1\), we get:
   \[
   (n^2 + 1)(n^2 c_n + 1) = n^2 (n^4 c_{n^2} + 1) + 1
   \]
   Expanding and simplifying, we obtain:
   \[
   n^4 c_n + n^2 + n^2 c_n + 1 = n^6 c_{n^2} + n^2 + 1
   \]
   \[
   n^4 c_n + n^2 c_n = n^6 c_{n^2}
   \]
   \[
   c_n (n^4 + n^2) = n^6 c_{n^2}
   \]
   Dividing both sides by \(n^2\), we get:
   \[
   c_n (n^2 + 1) = n^4 c_{n^2}
   \]

6. Since \(c_n\) must be an integer, \(n^4\) must divide \(c_n\). Therefore, we can write:
   \[
   c_n = n^4 d_n
   \]
   where \(d_n\) is some integer.

7. Substituting \(c_n = n^4 d_n\) into the equation \(c_n (n^2 + 1) = n^4 c_{n^2}\), we get:
   \[
   n^4 d_n (n^2 + 1) = n^4 (n^8 d_{n^2})
   \]
   Simplifying, we obtain:
   \[
   d_n (n^2 + 1) = n^8 d_{n^2}
   \]

8. Since \(d_n\) must be an integer, \(n^8\) must divide \(d_n\). Continuing this process, we see that \(d_n\) must be zero for all \(n\). Therefore, \(c_n = 0\).

9. If \(c_n = 0\), then \(b_n = 1\). Substituting \(b_n = 1\) back into \(a_n = n b_n\), we get:
   \[
   a_n = n
   \]

10. We verify that \(a_n = n\) satisfies the original equation:
    \[
    (n^2 + 1)n = n(n^2 + 1)
    \]
    which is true.

Therefore, the only sequence that satisfies the given condition is \(a_n = n\) for all positive integers \(n\).

The final answer is \(\boxed{a_n = n \quad \forall n}\).