Brute-force solver for the generalized Pell equation.