This can be done using long division that we have learned with numbers, except that each digit in the numeric long division is replaced with a number that can exceed 10.
Thus we can write the division as where the right most digit represent a number, and each number to the left represent an increasing power of x.
                 ________________________
1 +2 +1    |  1   +10   +13     + 39
We will use a first quotient digit of 1 and begin the division
                 _1______________________
1 +2 +1    |  1   +10   +13     + 39
                   1     +2     +1                                   (subtract)
                            8     12      39
After that, we have a multiplier of 8 and continue
                 _1___8___________________
1 +2 +1    |  1   +10   +13     + 39
                   1     +2     +1                                   (subtract)
                            8     12      39
                            8     16        8                         (subtract)
                                    -4      31
This means that we have a quotient of (x+8) with a remainder of -4x+31
thus the final expression looks like
