The sequence of polynomials $(a_n)$ is defined by $a_0=0$, $ a_1=x+2$ and $a_n=a_{n-1}+3a_{n-1}a_{n-2} +a_{n-2}$  for $n>1$.
 (a) Show for all positive integers $k,m$: if $k$ divides $m$ then $a_k$ divides $a_m$.
 (b) Find all positive integers  $n$ such that the sum of the roots of polynomial $a_n$ is an integer.
### Part (a)
We need to show that for all positive integers \( k \) and \( m \), if \( k \) divides \( m \), then \( a_k \) divides \( a_m \).

Given the sequence of polynomials \( (a_n) \) defined by:
- \( a_0 = 0 \)
- \( a_1 = x + 2 \)
- \( a_n = a_{n-1} + 3a_{n-1}a_{n-2} + a_{n-2} \) for \( n > 1 \)

We are given the form of \( a_n \) as:
\[ a_n = \frac{(3x + 7)^{F_n} - 1}{3} \]
where \( F_n \) is the Fibonacci sequence defined by \( F_0 = 0 \), \( F_1 = 1 \), and \( F_{n+1} = F_n + F_{n-1} \).

To prove this by induction:
1. **Base Case:**
   - For \( n = 0 \):
     \[ a_0 = 0 = \frac{(3x + 7)^0 - 1}{3} \]
   - For \( n = 1 \):
     \[ a_1 = x + 2 = \frac{(3x + 7)^1 - 1}{3} \]

2. **Inductive Step:**
   Assume the formula holds for \( n-1 \) and \( n-2 \):
   \[ a_{n-1} = \frac{(3x + 7)^{F_{n-1}} - 1}{3} \]
   \[ a_{n-2} = \frac{(3x + 7)^{F_{n-2}} - 1}{3} \]

   Then,
   \[
   a_n = a_{n-1} + 3a_{n-1}a_{n-2} + a_{n-2}
   \]
   Substituting the assumed forms:
   \[
   a_n = \frac{(3x + 7)^{F_{n-1}} - 1}{3} + 3 \left( \frac{(3x + 7)^{F_{n-1}} - 1}{3} \right) \left( \frac{(3x + 7)^{F_{n-2}} - 1}{3} \right) + \frac{(3x + 7)^{F_{n-2}} - 1}{3}
   \]
   Simplifying the expression:
   \[
   a_n = \frac{(3x + 7)^{F_{n-1}} - 1 + (3x + 7)^{F_{n-1}} (3x + 7)^{F_{n-2}} - (3x + 7)^{F_{n-1}} - (3x + 7)^{F_{n-2}} + 1 + (3x + 7)^{F_{n-2}} - 1}{3}
   \]
   \[
   a_n = \frac{(3x + 7)^{F_{n-1} + F_{n-2}} - 1}{3}
   \]
   Since \( F_n = F_{n-1} + F_{n-2} \), we have:
   \[
   a_n = \frac{(3x + 7)^{F_n} - 1}{3}
   \]
   Thus, the formula holds by induction.

Now, if \( k \) divides \( m \), then \( m = nk \) for some integer \( n \). We compare \( a_k \) and \( a_m \):
\[ a_k = \frac{(3x + 7)^{F_k} - 1}{3} \]
\[ a_m = \frac{(3x + 7)^{F_{nk}} - 1}{3} \]

It is well known that \( a^m - 1 \) divides \( a^n - 1 \) if and only if \( m \mid n \). Therefore, \( a_k \) divides \( a_m \) if and only if \( F_k \) divides \( F_{nk} \), which is a known property of Fibonacci numbers.

Thus, part (a) is proven.

### Part (b)
We need to find all positive integers \( n \) such that the sum of the roots of the polynomial \( a_n \) is an integer.

The polynomial \( a_n \) is given by:
\[ a_n = \frac{(3x + 7)^{F_n} - 1}{3} \]

Expanding the polynomial:
\[ a_n = 3^{F_n - 1} x^{F_n} + 7 \cdot F_n \cdot 3^{F_n - 2} x^{F_n - 1} + \ldots - \frac{1}{3} \]

The sum of the roots of a polynomial is given by the negative coefficient of \( x^{F_n - 1} \) divided by the leading coefficient. For \( a_n \), this sum is:
\[ -\frac{7 \cdot F_n \cdot 3^{F_n - 2}}{3^{F_n - 1}} = -\frac{7 F_n}{3} \]

For this to be an integer, \( F_n \) must be divisible by 3. This occurs when \( n = 4k \) for some integer \( k \).

Checking small values:
- For \( n = 1 \):
  \[ a_1 = x + 2 \]
  The sum of the roots is \(-2\), which is an integer.
- For \( n = 2 \):
  \[ a_2 = (x + 2) + 3(x + 2)(0) + 0 = x + 2 \]
  The sum of the roots is \(-2\), which is an integer.
- For \( n = 3 \):
  \[ a_3 = a_2 + 3a_2a_1 + a_1 \]
  The sum of the roots is not an integer.

Thus, the positive integers \( n \) such that the sum of the roots of \( a_n \) is an integer are \( n = 1, 2, 4k \) for \( k \geq 1 \).

The final answer is \( \boxed{ n = 1, 2, 4k } \) for \( k \geq 1 \).