Polynomial division challenge Let $x,y,n \in \mathbb{Z} \geq 3$, Find $A,B$ such that $$x^{n-1}+x^{n-2}y+x^{n-3}y^2+\cdots+x^2y^{n-3}+xy^{n-2}+y^{n-1}= A(x^2+xy+y^2)+B$$ What is the best method to approach this? 
 A: If $n=3m$, where $m\in\mathbb{Z}$, then the polynomial is exactly divisible by $x^2+xy+y^2$, and the result (using polynomial long division, see image below for some old fashioned pen and paper working) is 
$$A=\sum_{k=0}^{m-1}x^{n-3-3k}y^{3k}$$
while $B=0$.
For the other two cases, when $n=3m+1$ the remainder $B=y^{n-1}$, and for $n=3m+2$ we have $B=xy^{n-1}+y^n$ - the polynomial $A$ being same of the form, for these two cases
$$A=\sum_{k=0}^{m-1}x^{n-3-3k}y^{3k}$$
An alternative notation for the summation index for $A$ for all three cases (in terms of $n$) is as follows, making use of the floor function:-
$$A=\sum_{k=0}^{\left\lfloor\frac{n}{3}\right\rfloor-1}x^{n-3-3k}y^{3k}$$

A: Useful things: 
$$x^2 + xy + y^2 = \frac{x^3 - y^3}{x - y}$$
If $n$ is odd, then: $$LHS = \frac{x^n - y^n}{x - y}$$
But $A$ and $B$ are not clearly defined. In the current form of the question, we have infinitely many such $A$ and $B$. You must specify what they are.
A: As we have homogeneous polynomials, we first solve the problem for the de-homogeneised polynomials, setting $y=1$, then homogeneise the results.
So we have to  find  $A, B$ such that 
\begin{align*}
& x^{n-1}+x^{n-2}+x^{n-3}+\cdots+x^2+x+1= A(x^2+x+1)+B \\
\iff (&x-1)(x^{n-1}+x^{n-2}+x^{n-3}+\cdots+x^2+x+1)=A(x-1)(x^2+x+1)+B(x-1)\\
\iff\vphantom{(} & x^n-1=A(x^3-1)+B(x-1)
\end{align*}
Now let $r=n\bmod 3$. It is easy to check the quotient and the remainder of the division of $x^n-1$ by $\,x^3-1\,$ are: 
$$ A=x^{n-3}+x^{n-6}++\cdots+x^r, \quad B = x^r -1. $$
Hence, for the original problem with homogeneous polynomial, we'll have:
$$A=x^{n-3}+x^{n-6}y^3++\cdots+x^ry^{n-3-r},\quad B=x^ry^{n-3-r}-y^{n-3}. $$
