Pell'q equaation solver