Piyavskii’s algorithm