Also, might be easier to write this as `while div != 0` and put `return u` outside the loop. I don't have a strong opinion on that, but it's how I've seen most reference implementations write it.