Partial quotients algorithm