Determine all positive integers $n$ for which there exist $n\times n$ real invertible matrices $A$ and $B$ that satisfy $AB-BA=B^2A$.

[i]Proposed by Karen Keryan, Yerevan State University & American University of Armenia, Yerevan[/i]
1. **Reformulate the given equation:**
   \[
   AB - BA = B^2A
   \]
   We can rewrite this as:
   \[
   AB = B^2A + BA
   \]
   By multiplying both sides by \(A^{-1}\) from the right, we get:
   \[
   ABA^{-1} = B^2 + B
   \]
   This implies that \(B\) and \(B^2 + B\) are similar matrices, and hence they have the same eigenvalues.

2. **Analyze the eigenvalues:**
   Assume \(n\) is odd. Since \(B\) is an \(n \times n\) real matrix, it must have at least one real eigenvalue, say \(\lambda\). Consider the sequence of real numbers \(\{\lambda_i\}_{i=1}^{\infty}\) defined by:
   \[
   \lambda_1 = \lambda \quad \text{and} \quad \lambda_{i+1} = \lambda_i^2 + \lambda_i
   \]
   Since \(B\) is invertible, \(\lambda_i \neq 0\) for all \(i\). Notice that:
   \[
   \lambda_{i+1} = \lambda_i^2 + \lambda_i > \lambda_i
   \]
   for all \(i\). This implies that the sequence \(\{\lambda_i\}\) is strictly increasing. However, since \(B\) is an \(n \times n\) matrix, it can have at most \(n\) distinct eigenvalues. This leads to a contradiction because the sequence \(\{\lambda_i\}\) would generate infinitely many distinct eigenvalues. Therefore, \(n\) cannot be odd.

3. **Construct matrices for even \(n\):**
   For \(n = 2\), consider the matrices:
   \[
   A_2 = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}, \quad B_2 = \begin{bmatrix} -1 & 1 \\ -1 & -1 \end{bmatrix}
   \]
   We can verify that these matrices satisfy the given equation:
   \[
   AB - BA = B^2A
   \]
   For general even \(n\), we can construct block matrices by taking \(\frac{n}{2}\) copies of \(A_2\) and \(\frac{n}{2}\) copies of \(B_2\). Specifically, let:
   \[
   A = \begin{bmatrix} A_2 & 0 & \cdots & 0 \\ 0 & A_2 & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & A_2 \end{bmatrix}, \quad B = \begin{bmatrix} B_2 & 0 & \cdots & 0 \\ 0 & B_2 & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & B_2 \end{bmatrix}
   \]
   These block matrices will satisfy the given equation for any even \(n\).

\(\blacksquare\)

The final answer is \( \boxed{ n } \) even.