Pell's equation solver