Here's how I would do it.
The problem is in getting the numbers to line up.
I use "color(white)(X)" with as many Xs and other characters as needed to get the correct alignment.
For the horizontal lines I use "stackrel(—)" with as many m-dashes as needed for a proper line length.
It's a bit tedious, but it gives a reasonable answer..
I invite others to add their suggestions for formatting.
An alternative method using matrix structure
Here's what my version would look like. I find it easier to work with especially when adapting it for polynomial long division.
Without the opening and closing hashtags:
Use of the matrix structure avoids alignment problems but results in horizontal spacing that may appear unnatural.
You might also note that I've used separate lines for my horizontal strokes; this unfortunately (to my mind) increases the vertical spacing. The alternative, using stackrel, is possible:
but can lead to some messy code:
if you want a line above spaces with no real characters.
Here's what it looks like with stackrel: