Improved the divmod() function to include polynomials

Passed the tests on my machine.