I wonder if a divmod-ish approach would be faster here?