Stuck for D=61

The previous algorithm is silly.
For a given X and D, I could just get Y by simple solve the quadratic
equation.
Here comes the new algorithm. Anyway, it is still not acceptable, when
D=61, I need about 20 minutes to get the result (1766319049, 226153980),
which is composed by really large numbers.

I should be smarter to get this done.