Tag continued fraction algorithm